aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads:Pls. Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads:Pls. Help" Watch "Threads:Pls. Help" New topic
Author

Threads:Pls. Help

rashu gulati
Greenhorn

Joined: Nov 06, 2003
Posts: 12
Which is true abt the code below::
public class joining{
static Thread createThread(final int i,final thread t1)
{
Thread t2=new Thread(){
public void run(){
System.out.println(i+1);
try{
t1.join();
}catch(Interrupted Exception e){
}
System.out.println(i+2);
}
};
System.out.println(i+3);
t2.start();
System.out.println(i+4);
return t2;
}
public static void main(String[] args)
{
createThread(10,createthread(20,Thread.currentThread()));
}
}
Can anyone explain the sequence to me?
Thanks
Rashu Gulati
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Hi, this question was discussed in depth here.
Don Wood
Ranch Hand

Joined: Dec 05, 2003
Posts: 65
Goodness gracious, what test did this question come from? I suppose that given enough time and caffeine I could answer this one using only pencil and paper but it would be difficult to answer it and 60 other questions in two hours.
Is the complexity of this question representative of the questions on the exam?
[ January 09, 2004: Message edited by: Don Wood ]
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
Originally posted by Don Wood:
Goodness gracious, what test did this question come from? I suppose that given enough time and caffeine I could answer this one using only pencil and paper but it would be difficult to answer it and 60 other questions in two hours.
Is the complexity of this question representative of the questions on the exam?
[ January 09, 2004: Message edited by: Don Wood ]

A tricky part of the nested method calls and semantics like this is less likely to be there. Otherwise, the real questions on threads and GC are rather difficult and require practice to approach. Luckily, there are only about 10 of them that come on threads. I'd say, the thread and GC questions were the most challenging, so they are worth revisiting a few times.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Threads:Pls. Help