Comments (13)
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.
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.
The problem is still exist even if i set it to 100ms
from progressbar.
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.
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.
What is pb.stepTo()
? You should use step()
to advance by 1, or stepTo(n)
to directly step to n.
from progressbar.
You can use a debugger and pause when your program is stuck to see at which stack frame it is being stuck.
from progressbar.
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.
@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.
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.
See https://github.com/bwittwer/progressbar/tree/issue/13 for a unit test reproducing the issue.
from progressbar.
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.
@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)
- Seems to be a bug with early closing the terminal HOT 1
- progress bar looks strange HOT 2
- Progress bar not show Block in cmd.exe & powershell.exe
- Know if progress bar have max value or it is set to infinity? HOT 1
- Work around bugs in java.util.Spliterator#estimateSize HOT 2
- ProgressBarBuilder should allow custom ProgressBarRenderer implementation HOT 1
- IntelliJ IDEA - Maven test run not showing progress bar HOT 5
- Multiple progress bars end up on a single line under osx with 0.9.4 HOT 6
- ProgressBarBuilder()#setEtaFunction is pointless because all methods in ProgressState are package-private HOT 3
- progressbar cannot be used as a module HOT 2
- Ctrl - c to stop java console program slowly HOT 2
- Allow users to setup their own style HOT 4
- Add Automatic-Module-Name to jar manifest HOT 3
- Real module-info.java HOT 2
- Feature: Support for Stacked/Styled Progress-Bars HOT 1
- Impossible to use in a fully modular application with finely grained jline libraries. HOT 3
- Progressbar error:Exception in thread "main" java.lang.NoSuchMethodError: org.jline.terminal.TerminalBuilder.dumb(Z)Lorg/jline/terminal/TerminalBuilder; HOT 1
- How to change Text Color HOT 1
- Using ProgressBar constructor and building it using ProgressBarBuilder yields different results HOT 1
- Question: Customize progress bar a bit ...
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from progressbar.