Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

can we use run() method twice in java threads?  RSS feed

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

One of the question, which I was asked by is "can we use run() method twice in java threads?"

he said it is possible, could you please give me some suggestion to run twice?
 
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean you want the run method of thread/runnable to be invoked more than once when a thread is started? That's possible. Take a look at http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ScheduledExecutorService.html for example.
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect the devil is in the wording details of such a question. Aside from what Jaikiran said, you can invoke the run() method of a Runnable any number times directly - keeping in mind that will not start a new thread. What you can not do is invoke the start() method twice. So it depends on what the exact question was.
 
saidi Bandi
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here we will start the thread once and expecting to run, the run() method twice...

I asked him for some clue, he said, we can do by configuring some details in the constructor.......
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the constructor of which class?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!