Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Share CPU with other threads during a loop 2

Status
Not open for further replies.

groehrbein

Technical User
May 29, 2004
2
DE
Hello,

I've written a simple method that reads a huge file from disk into memory. Before starting that I show a thread with a clock.

But the window is created only without the clock and it stays transparent except the border and the caption with system menue and so on.

So I want to allow the clock window to work during the loop.


I do not have any idea how to realize this with java. I've tried a lot but nothing works.

Is there an easy way to solve this problem?


Best regards
Gerald
 
Disk I/O is pretty CPU intensive.
Try adding a Thread.yield() or a Thread.sleep(250) to the method that reads the file and create a loop where you read only 4K bytes at a time.
 
Hello,
thanks a lot for all your help.

I hope the yield method will work. Under Windows I have done a lot of C programming and the yield method was there used in a nonpreemptive multitasking environment.

Using yield sounds to me tha Java implements a nonpreemptive multitasking model as a default for Swing's event model? Is this right?

After reading the docu at the links given by Sedj I think there should although be a preemptive way. I've done some tests with some of the thread functions but I'am a lazy bone.

I think for one simple progress bar it looks like a lot of work to implement the whole thread save code.

best regards
gerald
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top