• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Have other apps run, too

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic