• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Tomcat restful with a queued thread  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I wish to make a Tomcat driven rest service, where a PUT's a string that represents a filepath.
The server then adds this to a queue, and performs a long job on each member of the queue.
The client can do a GET with the same path, and the server will respond with a status string.

How would you setup the queue, so that the POJO that implements the PUT can put it on the queue.
And where would you imagine the process that implements the long job to exist?

I am very new to Tomcat and to producing Rest services, as you probably can see.
I would like someone to point me in the right direction please with a rough idea as to how this could be implemented.

Regards,
John.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem should not be the RESTful archtitecture but this:

And where would you imagine the process that implements the long job to exist?



That is the key design decision.

If the long job is executed as a Thread in the JVM that is executing Tomcat, that is potentially very limiting. Could you had the job off to another computer entirely, using something like JavaSpaces or JNI?

Bill
 
John Blunket
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill,

The reason I want the Tomcat server to tun the long job, is that it is the "other server".
My main application will run on a users PC, but there is a part that requires quite some muscle, and time. This is the bit that I intended to hive off to another server running Tomcat.

Maybe I should be using a servlet. In the ini method I can start up a queue, and a thread to do the main grunt.

The doPut method will provide the path, and push it onto the queue.

What do you think of that idea?

John.
 
Bartender
Posts: 20721
124
Android Eclipse IDE Java Linux Redhat Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
REST services aren't dependent on what appserver you use. It can be Tomcat, it can be WebLogic, it can be JBoss. The app logic will be the same.

An "engine servlet" works, although these days, it's preferable to launch the engine off a ContextListener rather than a servlet init().
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far this sounds quite feasible.

Does one of these long-running compute intensive jobs consume all of the server memory/cpu resources? If not, you might implement a pool of Threads so that more than one job can be running "at the same time."

If your long-running job involves a lot of IO and/or database access, you would probably find the cpu has plenty of spare cycles. If your initial design allowed for multiple worker Threads, you could adjust the number available to optimize throughput.

In any case measure what the server is doing with a single job.

Bill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!