• 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

newbie a help is appreciated

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well i m a newbie here just a beginner in java wanted to hv an explanation on this peice of code


hope any one can help me with this
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's your question?
 
satya mohanty
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my ???

1.wht are those last three lines indicate i mean i know am creating threads here but why do i need the 2 statements there.


2.passing object and thread name as parameters wht happens when i m passing a runnable object as parameter.
3.why is this statement written in MYthread constructor


actually wht does this mean.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. The first line creates a runnable, which is used in the next two lines to create two different threads that share the runnable. It is unfortunate that you named your runnable "MyThread".

2. The runnable object is used by the thread to... well... to run (ie. to call the run() method).

3. Your runnable object creates a thread object internal to it -- and it doesn't do anything with it.

actually wht does this mean



The Sun tutorial on threads is a place to start here...

http://java.sun.com/docs/books/tutorial/essential/concurrency/

Henry
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

satya mohanty wrote:
1.wht are those last three lines indicate i mean i know am creating threads here but why do i need the 2 statements there.


If you are talking about last two statements (with t2 & t3) then they are creating two threads to run simultaneously. Thread constructor is passed a runnable object (t1 - MyThread) which is what the thread will be executing on.

2.passing object and thread name as parameters wht happens when i m passing a runnable object as parameter.


No problem. Thread has few constructors you can use. If you passed in a name you may identify the thread later easily by name.


3.why is this statement written in MYthread constructor


That thread doesn't do anything here. It's that two threads namely t1 & t2 do the actual job.
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And Welcome to JavaRanch
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic