Coder Social home page Coder Social logo

Comments (13)

ctongfei avatar ctongfei commented on August 16, 2024

Stuck? Does your program finish (exited with return value 0) normally? Or some exception was thrown? Or the progressbar simply did not reach 100%, but the control flow continued?

from progressbar.

rholdberh avatar rholdberh commented on August 16, 2024

Progress bar reaches 100% and my application not going forward. I am getting something like this:

Collecting rows 100% ││ 4/4 (10:59:00 / 0:00:00)

I was investigating the problem and probably problem is in default updateInterval.
It is set to 1000ms. But if collection is faster then 1000ms (in this case only 4 rows was returned), soI am getting out of loop faster then progress bar get refreshed if I understand well.

from progressbar.

rholdberh avatar rholdberh commented on August 16, 2024

The problem is still exist even if i set it to 100ms

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

Progressbar runs on a separate thread rather than your main thread. It should never obstruct your program flow. Are you sure that this is a problem caused by progressbars?

Could you copy the snippet around the code here?

from progressbar.

rholdberh avatar rholdberh commented on August 16, 2024
ProgressBar pb = new ProgressBar("Collecting  rows", rowsCount);
 //int pr=0;
try {
            ResultSet rs = stm.executeQuery(query);
            ResultSetMetaData rsmd = rs.getMetaData();
            int columnsNumber = rsmd.getColumnCount();

            pb.start();

            while (rs.next()) {
                pb.stepTo();
       
              //  pr++;
              //  System.out.print("\rCollecting ..."+pr+"/"+rowsCount);

                StringJoiner result = new StringJoiner(";");
                for (int i = 1; i <= columnsNumber; i++) {
                    String value = rs.getString(i);
                    if(value == null) value="null";
                    result.add(value.trim());
                }
                results.add(result.toString());
            }

        pb.stop();

        } catch (SQLException e) {
            e.printStackTrace();
        }

This is my code. To make sure that the program stacks because of progress bar I have comment out progress bar code and add a simple progress implementation through the System.out.print (commented in the code). This is only one place where I use the progress bar. It is a simple java application to get records from database, convert to proper format and write to csv. One thread application.

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

What is pb.stepTo()? You should use step() to advance by 1, or stepTo(n) to directly step to n.

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

You can use a debugger and pause when your program is stuck to see at which stack frame it is being stuck.

from progressbar.

bwittwer avatar bwittwer commented on August 16, 2024

Hi,

I have a similar behaviour: the progressbar does not give the hand back to the calling application (based on Spring Shell), the ProgressThread thread is still running (time counting in the console).

A thread dump is showing that the application thread is stuck in the me.tongfei.progressbar.ProgressBar.stop() method.

Here is the dump extract:

Thread Spring Shell: 
  at java.lang.Object.wait(long)
  at java.lang.Thread.join(long) (line: 1245)
  at java.lang.Thread.join() (line: 1319)
  at me.tongfei.progressbar.ProgressBar.stop() (line: 103)
  at <<myapp>>.FileService.writeToFile(java.util.Collection, java.io.File) (line: 97)
  at <<myapp>>.FileService.writetemKeysToFile(java.util.Collection, java.io.File) (line: 64)
  at <<myapp>>.BrowseCommands.listkey(java.lang.String, java.lang.String, java.io.File) (line: 80)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(java.lang.reflect.Method, java.lang.Object, java.lang.Object[ ])
  at sun.reflect.NativeMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[ ])
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(java.lang.Object, java.lang.Object[ ])
  at java.lang.reflect.Method.invoke(java.lang.Object, java.lang.Object[ ])
  at org.springframework.util.ReflectionUtils.invokeMethod(java.lang.reflect.Method, java.lang.Object, java.lang.Object[ ]) (line: 196)
  at org.springframework.shell.core.SimpleExecutionStrategy.invoke(org.springframework.shell.event.ParseResult) (line: 68)
  at org.springframework.shell.core.SimpleExecutionStrategy.execute(org.springframework.shell.event.ParseResult) (line: 59)
  at org.springframework.shell.core.AbstractShell.executeCommand(java.lang.String) (line: 134)
  at org.springframework.shell.core.JLineShell.promptLoop() (line: 533)
  at org.springframework.shell.core.JLineShell.run() (line: 179)
  at java.lang.Thread.run()

Thread Thread-20: 
  at java.lang.Thread.sleep(long)
  at me.tongfei.progressbar.ProgressThread.run() (line: 120)
  at java.lang.Thread.run()

The code is quite similar to the code above.
I hope this can help.

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

@bwittwer I'll look into this. Seems to be a problem with threads. From what you've pasted, it seems that the progressbar thread died in Thread.sleep, which is very weird. It should only sleep for the given amount of milliseconds.

from progressbar.

bwittwer avatar bwittwer commented on August 16, 2024

Thanks for the reply.
It occurs randomly when the processing is very fast (a few line to write in a file for example).
It should be a timing issue as adding an explicit call to Thread.sleep(1000) before calling the ProgressBar.stop() will avoid the issue. It is like if the ProgressThread is not yet ready when receiving the stop().
I will create a junit to reproduce.

from progressbar.

bwittwer avatar bwittwer commented on August 16, 2024

See https://github.com/bwittwer/progressbar/tree/issue/13 for a unit test reproducing the issue.

from progressbar.

bwittwer avatar bwittwer commented on August 16, 2024

The problem comes from the run() method of the thread being sometimes called after the kill() was made.
A simple fix would be to check against a killed status rather than the running status in the thread as you control when you kill it but you do not have full control of when is it actually started.
See PR #15

from progressbar.

ctongfei avatar ctongfei commented on August 16, 2024

@bwittwer Thanks a lot :-) That's a subtle bug! it'll be uploaded to Maven Central as v0.5.5.

from progressbar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.