• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threads

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a quick question about threads:
Look at the following segment of code for executing a thread:
1)class MyThread immplements Runnable
..{ Lots of code}...
30)MyThread mt = new MyThread
31)Thread newThrd = new Thread(mt);
Obviously this is proper....my question is, is the following ALSO proper(i.e. Will it compile & not though any exceptions?)
No line 30...INSTEAD:
Thread newThrd = new Thread(new MyThread)
Can you do that?
Thanks!
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi roger
Thread newThrd = new Thread(new MyThread());
this line is very much valid as the Thread class has a constructor which accepts a Runnable target as an argument.
infact even if MyThread were to extends Thread then too this line of code would be valid since the Thread class itself implements the Runnable interface
Hope that answers the question
Samith.P.Nambiar
----------------------------------------
The harder u try the luckier u get
----------------------------------------
 
You will always be treated with dignity. Now, strip naked, get on the probulator and hold this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic