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.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread" Watch "Thread" New topic


Roger Chan
Ranch Hand

Joined: Nov 13, 2001
Posts: 30
The following is a mock exam question:
public class Test extends Thread
String msg = "default" ;
public Test(String s)
msg = s;
public void run()
public static void main(String args[])
new Test("String1").start();
new Test("String2").start();
The explanation for this question is that there are three threads running in this program, main thread and two others. The order of thread execution is not guranteed. But when I compile and run this code snippet on Win98, the "end" always come before "String1" and "String2". Is this occur depending on the OS?
My question is whether the order of output is totally random or "end" always come before "String1" or "String2".
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
Order of thread execution completely depends upon the underlying platform. If it behaves like you said on Win98 it may behave completely different on other architecture. You cannot rely on the result of one platform to deduce the "universal" behavior of a multithreaded program.
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
[This message has been edited by Valentin Crettaz (edited November 25, 2001).]

[Blog] [Blogroll] [My Reviews] My Linked In
I agree. Here's the link:
subject: Thread
It's not a secret anymore!