Hi. I'm new to multi-threaded programming and I just wanted to get some insights on how to approach this problem.
I'm trying to create a web service that launches a process on remote computer. This part is actually done.
user->Web service->remote machine executes the given command->Web service->report back to user.
Now I need to make this accessible by multiple users. Please look at the attached picture for the schema.
These are components of the
servlet, which will do all the coordination work.
Incoming Job Listener and Job Completion Listener will be running until servlet is terminated. They will be running on a seperate
thread.
The Job Queue will be a blocking queue. Servlet will be checking job queue periodically to keep things running.
The job itself is executed on a remote machine. I'm thinking about opening a seperate socket on Completion listener so the remote machine report to this listener, not directly back to the servlet.
So here are my questions.
0. Is that scheme viable?
1. Will blocking queue do the job? The scenario I'm concerned is when multiple users submit a job at the same time, and when a job is submitted while the queue is being accessed for pulling the job out for execution(and vice versa).
2. What is a commonly used method of making threads talk to each other? I'm talking about the communication between the completion listener and the Job queue.
Thanks in advance!
EDIT: I am using
Tomcat as the container. My servlet does not implement SingleThreadModel interface.