[concurrency-interest] thread cancellation prob

Mubeen Shah mubeenshah at gmail.com
Sat Mar 28 08:42:17 EDT 2009


Hope you all doing very well.

I have a software (spring app) which is basically crawling the web pages,
and I want to control that crawling execution (start, stop and check status)
from other application using web-service, I need to expose three operations:
start, stop and check. Please check the design below:

I have one Crawler class extending the Thread class (Singleton):

public class Crawler extends Thread {

// ... some code here

private static Crawler obj;

private volatile boolean isRunning = false;

private Crawler(){


public synchronized static Crawler getInstance(){

if(obj == null){

obj = new BusinessObject();


return obj;


public void run(){


// Crawling the webpages and storing html in DB.



public void stopCrawler(){

isRunning = false;


public boolean status(){

return isRunning;




I have one web-service class extending ServletEndpointSupport (spring

public class CrawlerManagerService extends ServletEndpointSupport {

Crawler crawler = Crawler.getInstance();

public String start(){

if( !crawler.status() ){



return "RUNNING";


public String stop(){




return "NOT-RUNNING";


public String status(){

return ( ( crawler.status )?"RUNNING":"NOT-RUNNING");



I exposed 3 methods:

start(); // to start the process in thread (i just want a single thread)
stop(); // to stop the thread
status(); // check the current status of that thread

But everytime i am calling this webservice its creating a new thread and
starting service. for now i did one workaround to fix this issue:

I am searching all running threads:

Thread[] allSystemThreads; // suppose i have all running threads in system


Crawler crl = null;

for(Thread t : allSystemThreads){

if(t instanceof Crawler){

crl = (Crawler) t;




if(crl != null){

// i found the thread now i can start, stop and check status here


but i am not sure if its a good way to search for all threads and do the
required operation. can you please advise any possiblity in
java.util.concurrent package to utilize it in a standard way? so that i dont
need to go deeply to manage the threads. Please help me.

Looking forward to hear from you.

Mubeen Shah
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090328/1b20d990/attachment.html>

More information about the Concurrency-interest mailing list