Java Reference
In-Depth Information
This is a really poor chat implementation, as messages could be lost for clients that are re-
polling, but hopefully it illustrates how you might create such an application. In Chapter 27 ,
we'll implement a more robust and complete chat service.
NOTE
With protocols like WebSocket [ 13 ] and Server Sent Events (SSE) [ 14 ] being supported in most
browsers, pure HTTP server push and pub-sub are fast becoming legacy. So, if you're only going to
have browser clients for this kind of app, you're probably better off using WebSockets or SSE.
Priority scheduling
Sometimes there are certain services that are highly CPU-intensive. If you have too many of
these types of requests running, you can completely starve users who are making simple, fast
requests. To resolve this issue, you can queue up these expensive requests in a separate
thread pool that guarantees that only a few of these expensive operations will happen concur-
rently:
@Path ( "orders" )
public
public class
class OrderResource
OrderResource {
Executor executor ;
public
public OrderResource {
executor = Executors . newSingleThreadExecutor ();
}
@POST
@Path ( "year_to_date_report" )
@Produces ( "application/json" )
public
public void
void ytdReport ( final
final @FormParam ( "product" ) String product ,
@AsyncResponse response ) {
executor . execute ( new
new Runnable () {
public
public void
void run () {
Report report = generateYTDReportFor ( product );
response . resume ( report );
}
}
}
protected
protected Report generateYTDReportFor ( String product ) {
 
Search WWH ::




Custom Search