Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Have other apps run, too  RSS feed

 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Java app that uses threads.
Question is, how do you get it to yield so other (non-java) apps can have a chance to run, too?

yield() don't work. Or is it dependent on the OS?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally this should be the operating system's responsibility, but on some old systems, the OS really doesn't do it well (Windows 95/98/ME, for example, or a phone).

If you call Thread.sleep(), the OS ought to be able to schedule other applications while yours is sleeping. You're correct that yield() would have no effect on such a system.
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep. I noticed that on W2000 OS it hardly relinquishes it. XP manages it better.

What can I do as I have it running on W2000?

I don't want to use sleep().
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you could try to bump the priority of the other program -- by running it via the "start" command specifying a priority.

Henry
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows 2000 should multitask just as well as XP -- XP is pretty much the same OS, with a prettier face. Does the W2000 machine perhaps not have enough memory to swap your applications in and out efficiently?
 
Martin Mathis
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Karen Baog:
I don't want to use sleep().


Just curious, but what's wrong with using sleep()?
 
Oliver Smith
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Presumably it's not fine grained enough. Maybe you don't want to force your thread to always wait 1 second between iterations of a loop, but you don't mind if it does because other threads are busy.

I like to think yield() should be along the lines of "sleepUntilMyNextSliceIfThereAreThreadsInReadyState". If the rest of the threads are all sleeping or pending, then yield() should more-or-less do nothing.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!