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"
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.
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.