Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

executing thread only once

 
Mario Gimenez
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, this is my problem.

I have a class bo.
and two classes producer (runnable)
and consumer (runnable)

in bo I do producer.start() and consumer.start().
I need executing only once this operation via web.
I mean If the user clic a button then execute the bo and starts the threads.
but If I the user clic again I need to set a String like "running"

Thanks for your help!.
 
Sujoy Choudhury
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can handle it in the client side itself.
When the user clicks for the first time change the caption to "Running..." and programatically don't make a call to the server side again.
You can easily do it I guess.
 
Sudarshan Devardekar
Greenhorn
Posts: 4
Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Approach suggested by Sujoy Choudhury is best to use for web application.

Here is other way you can restrict thread execution number:
Use a ThreadGroup. Create your thread in a ThreadGroup. You get active thread count from a ThreadGroup, which you can use to check how many threads are present and can prevent creation of new thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic