• Post Reply Bookmark Topic Watch Topic
  • New Topic

RIght design pattern for web service - singleton  RSS feed

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

I plan to create a webservice (in Tomcat) that works with a certain file on the system and make some system calls. The challenge am having is to make sure only 1 request can be processed at a given time and the previoius request needs to be pre-empted.

Any ideas how this can be achieved?

Thanks,
V
 
Wim Vanni
Ranch Hand
Posts: 96
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean by 'pre-empted' but designing for a single request can be achieved in different ways. First thing that comes to mind reading your question are threads. May sound a bit weird considering threads is mostly used for parallel processing but you can make it so only a single thread runs while the others sleep.

Cheers,
Wim

Edit: Oh, and welcome to the Ranch!
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using servlets, you can make the servlet implement SingleThreadModel, although it's deprecated. A probably better solution is to use synchronization - you can use the class object to synchronize on to ensure that only one instance will enter the synchronized block at a time. This will make the new request come after the old request though, not preempt it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!