This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes initializing thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "initializing thread" Watch "initializing thread" New topic

initializing thread

saravanan ragunathan
Ranch Hand

Joined: Aug 02, 2010
Posts: 84

the above code is executed successfully
but for experimental purpose when i write the below code
to start only the last thread i have will generate
compilation error("variable t might not have been initialized")
is there is any problem in this

"I Love Java Ranch"
Rob Spoor

Joined: Oct 27, 2005
Posts: 20183

What will happen if you change that 10 into a 0? The compiler thinks in a similar way. It can't guarantee that t will have a value after the loop.

How To Ask Questions How To Answer Questions
K Abhijit
Ranch Hand

Joined: Mar 03, 2008
Posts: 88
It's Just a Compilation error: The local variable t may not have been initialized

unless any reference is target of assignment operator, compiler would not allow to use its L value..

simply assign null and then proceed

needless to say that there is a chance of NullPointer incase it bypasses for loop

“The difference between 'involvement' and 'commitment' is like an eggs-and-ham breakfast: the chicken was 'involved' - the pig was 'committed'.”
I agree. Here's the link:
subject: initializing thread
jQuery in Action, 3rd edition