[java] threads

Started by
13 comments, last by mill-o 22 years, 5 months ago
okay.. i did as you suggested and it works, more or less. i wrote a class Progress which can be seen below.

      class Progress {    private int progress;	    public Progress() {        progress = 0;    }	    public int getProgress() {        return progress;    }	    public void incProgress() {        progress++;    }}// --------------------------------------------------------// update progress, in the class that does the calculationsprogress.incProgress();SwingUtilities.invokeLater(new Runnable(){    public void run() {        progressMonitor.setProgress(progress.getProgress());    }});      


the thing is that now the whole task takes 17000 ms to complete instead of 8000 ms. is this the price i have to pay or i'm doing something wrong?



______________________________
catch (SpellingException e) {}

Edited by - mill-o on November 12, 2001 2:19:21 PM

Edited by - mill-o on November 12, 2001 2:19:37 PM
_______________________ http://mill.3dfxsweden.net
Advertisement
The only thing I can think of is that you''re updating the progressbar a LOT... That''s the only reason that solution should be slower. If you''re updating the bar more than a few hundred times, I''d say it''s worth looking into updating it far less often.
hehe okay, sounds reasonable. the textfile i''m using to test the program with contains ~200000 lines of text and i''m updating the progress bar in a loop which loops for every line, in other words, 200000 updates

i''ll fiddle a little and post the new results later tonight
_______________________ http://mill.3dfxsweden.net
If more than one thread accesses the same instance of your Progress-class you should also make the methods called synchronized.

-Neophyte

- Death awaits you all with nasty, big, pointy teeth. -
it works great now that i''m only updating two times every second. thanks a lot everyone
_______________________ http://mill.3dfxsweden.net

This topic is closed to new replies.

Advertisement