Posted By:
Brian_Tsang
Posted On:
Wednesday, July 19, 2006 10:13 PM
Hello All Guru, Hope someone can shed some lights here please. I am working on a multiple search tasks web-app with a requirement to provide an intermediate screen to display each selected search task status, e.g. "processing", or a number of result returned. This is what I'd done so far: 1. Upon receiving the search request I kick off a thread for each target search task. i.e. if three target sites are specified there will be three search agent threads running for each of the search task. 2. Each thread generates an ArrayList of result and put it into the session then I flag it to stop/kill itself by setting/checking a boolean variable in their "run&qu
More>>
Hello All Guru,
Hope someone can shed some lights here please.
I am working on a multiple search tasks web-app with a requirement to provide an intermediate screen to display each selected search task status, e.g. "processing", or a number of result returned.
This is what I'd done so far:
1. Upon receiving the search request I kick off a thread for each target search task. i.e. if three target sites are specified there will be three search agent threads running for each of the search task.
2. Each thread generates an ArrayList of result and put it into the session then I flag it to stop/kill itself by setting/checking a boolean variable in their "run" methods.
3. My main process, the coordinating servlet (say PerformSearch) dispatches a status page (JSP) and the status page then enters a 10 seconds polling state until the user press a "Stop" button, for which I send a request to stop the polling and get the individual list and combine/sort them to a final list before dispatching it to the user.
So far so good. I can simulate the "wait for more" and interrupt states of the behaviour. But, when I start another browser to kick off another search on different search word, the worker threads seem to mingle the results.
e.g. say in 1st search task, browser A, I specify "beijing" and kick off the threads and they go ahead to search the selected target (it's web-sites or databases). While the 1st search tasks' threads are still running, 1 or 2 threads may return and indicate they have result during the status polling, and the rest of the threads ( form other search targets) may still be running due to the nature of the target sites/databases ( slow response, unavilable, etc. ). At this time if I start another brower, say browser B ( or separate window of the same browser - supposedly they're separate http session ) and kick off a 2nd search task on "taiwan" then those threads still runnning may receive this new search term and suddenly decided to put the search result of the "taiwan" into part of its generating result list !!! Disaster ! Know what I mean?
So, my question are:
1. Does java thread not live within a session?
2. As I gathered, you can't call Thread.stop() now, is there any better way to end a running thread?
3. How can I avoid this data mingling from happening?
Really hope someone can give any clue/hints please.
Appreciate that in advance.
Cheers
-Brian
<<Less