aspose file tools*
The moose likes Tomcat and the fly likes Tomcat restful with a queued thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat restful with a queued thread" Watch "Tomcat restful with a queued thread" New topic
Author

Tomcat restful with a queued thread

John Blunket
Greenhorn

Joined: Oct 06, 2009
Posts: 12
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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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

Joined: Oct 06, 2009
Posts: 12
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.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

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().


Customer surveys are for companies who didn't pay proper attention to begin with.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat restful with a queued thread