File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes newbie a help is appreciated Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "newbie a help is appreciated" Watch "newbie a help is appreciated" New topic
Author

newbie a help is appreciated

satya mohanty
Greenhorn

Joined: Oct 03, 2009
Posts: 5
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
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11527
    
100

What's your question?


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
satya mohanty
Greenhorn

Joined: Oct 03, 2009
Posts: 5
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.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19073
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

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.

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3860

And Welcome to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: newbie a help is appreciated