• 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

executing thread only once

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!.
 
Ranch Hand
Posts: 136
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic