my dog learned polymorphism*
The moose likes Threads and Synchronization and the fly likes Multithreading on Linux Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Multithreading on Linux" Watch "Multithreading on Linux" New topic
Author

Multithreading on Linux

Drew Lane
Ranch Hand

Joined: May 13, 2001
Posts: 296
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 ]
Marcos R Oliveira
Ranch Hand

Joined: Apr 20, 2002
Posts: 51
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.

Hope this can help you,
Marcos.


SCJP 1.4 - SCJP 1.6 - SCWCD in progress
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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
Ranch Hand

Joined: Apr 20, 2002
Posts: 51
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.
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
It happens the same in Mandrake 9.0


SCJP2. Please Indent your code using UBB Code
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
On Suse 8.1 it gives a couple of hundred Foos then sticks a few seconds, and then goes into a Foo-Bar flip-flop.
-Barry
[ November 15, 2002: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Multithreading on Linux
 
Similar Threads
Decode Password from .htaccess file?
Welcome!
Passed SCJP with 84%
Which part of Java is sexy for you?
Anyone Uses Linux and ONLY Linux?