The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes A thread problem 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 "A thread problem" Watch "A thread problem" New topic

A thread problem

sabah ammar

Joined: Jan 10, 2005
Posts: 23
hi pals,
i got this question
public class PrintJ extends Thread{
int j=0;
public void run(){
}catch(Exception e){
public static void main(String []a){
PrintJ t1=new PrintJ();
Q.What you have to do to ensure that j will print 100? have to make t1 as Daemon Thread. have to join t1 to main.
C.value of j is set to 100; have to interupt the main method.

Please describe the answer to me which accordingly is option B.thank you very much.
Joyce Lee
Ranch Hand

Joined: Jul 11, 2003
Posts: 1392
Hi Sabah,

To make sure 100 (not 0) is printed, join() of t1 must be called before System.out.println statement.

By calling t1.join(), it suspends the current thread, i.e. the main thread in this case, until t1 thread is completed.

[ February 26, 2005: Message edited by: Joyce Lee ]
sabah ammar

Joined: Jan 10, 2005
Posts: 23
exactly, main was suspended in other very worried about threads for the exam...
anyways, thank you very much joyce .
I agree. Here's the link:
subject: A thread problem
jQuery in Action, 3rd edition