This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I understand that Solaris uses preemptive tasking for multithreading, and that Windows uses timeslicing, but what does Linux use (with respect to Java, of course)? Thanks! Drew [ November 13, 2002: Message edited by: Drew Lane ]
Hi, Drew! I am not sure what type of tasking Linux uses, but below is a code that can help you to find out. If you run the application and the messages "Foo" and "Bar" alternate then Linux uses timeslicing. If "Bar" is never printed then Linux uses preemptive multitasking.
Why would preemptive multitasking prevent the "Bar" thread from running? When "Foo" notifies and waits, that should be enough to wake "Bar" up.
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Marcos R Oliveira
Joined: Apr 20, 2002
Oh! I�m sorry! In the code above I put a wait() call and the method imprime() to make a test. The code below is what I wanted to show here.
With this example, in a preemptive multitasking, "Bar" will never have the chance to be printed, while in a timeslincing "Foo" and "Bar" can be seen. Thanks, Ron, Marcos.
Joined: Jun 06, 2002
On MacOS X 10.2.2, which is based on BSD Unix, you see both "Foo" and "Bar'", but they do not alternate one for one. Instead, I get long stretches of Foo, followed by long stretches of Bar, then back to Foo, etc.