aspose file tools*
The moose likes Threads and Synchronization and the fly likes Is this correct ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Is this correct ?" Watch "Is this correct ?" New topic
Author

Is this correct ?

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
I read this on the net.
You can start a thread "inline" without implementing Runnable or extending Thread class

( new Thread() { public void run()
{
// do something
} } ).start();

This actually is extending the Thread class. Then in that case what is an inline thread ?
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
You are correct. What you have shown is what you read about.
It is the "in-line" version, or one line of code...

Jim ... ...


BEE MBA PMP SCJP-6
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36508
    
  16
That looks to me like an instance of an anonymous inner class.
Elchin Asgarli
Ranch Hand

Joined: Mar 08, 2010
Posts: 222

It is correct, but its extremely ugly, so never do it at the job


Personal page, SCJP 6 with 91%, SCWCD 5 with 84%, OCMJD
getshijos joseph
Greenhorn

Joined: May 28, 2010
Posts: 5
Yes this is correct ...but not a best practice

javarecharge.com


admin
www.javarecharge.com
||||||||||||||................
Wanna recharge
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

Campbell Ritchie wrote:That looks to me like an instance of an anonymous inner class.

definitely! (I think so)


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

jose chiramal wrote:I read this on the net.
You can start a thread "inline" without implementing Runnable or extending Thread class

( new Thread() { public void run()
{
// do something
} } ).start();

This actually is extending the Thread class. Then in that case what is an inline thread ?


this is currrect..we can do this because here we are creating a thread class instance using new.
and thread class itself implementing a runnable interface remember it is overriding public void run() method.

So it is surely possibly.........

SCJP6.0,My blog Ranchers from Delhi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is this correct ?
 
Similar Threads
start() kicks start() but not run() why?
Thread Execution
Inline thread
Why start() method
Thread vs Runnable