• 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

Need some help on multi-threaded programming

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
flow.jpg
[Thumbnail for flow.jpg]
flowchart
 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe, exposing the WebService to the public will make it usable to one-and-all.
 
Ranch Hand
Posts: 443
3
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect this is more a J2EE question ...

Your running on a J2EE container (Tomcat), generally you shouldn't create threads or open remote sockets directly. Do you intend this to run over a local LAN or the world wide web ?

If you can your job should be submitted to your containers work manager (all threading done by it, I'm not sure which J2EE version your Tomcat supports), the result of the job would be stored on the session (possibly backed for a db) and effectively polled for by your front end or use a messaging solution such as JMS your client then being a JMS listener for job completes. Tomcat I think only implements the client bits of the latest J2EE standard so you might want to move to Glassfish.

If it must be across the web and you don't want to be a JMS client and it must be realtime so you can't poll you need to look at web sockets (Glassfish supports these) but this is very shiny and new, it allows bidirectional communication i.e. the server can push data back to the client an your client can have a job complete event.

If your using Tomcat and everything is local LAN , one non clustered JVM then you could just open sockets , spawn threads, its all just Java but be aware you are not using the container in the way it was intended.

hope that helps ...
 
reply
    Bookmark Topic Watch Topic
  • New Topic