File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

newbie a help is appreciated

 
satya mohanty
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 11833
181
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's your question?
 
satya mohanty
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Vijitha Kumara
Bartender
Posts: 3909
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • 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: 3909
9
Chrome Fedora Hibernate
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic