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.
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-
@Path ( "orders" )
public class
class OrderResource
OrderResource {
Executor executor ;
public OrderResource {
executor = Executors . newSingleThreadExecutor ();
@Path ( "year_to_date_report" )
@Produces ( "application/json" )
public void
void ytdReport ( final
final @FormParam ( "product" ) String product ,
@AsyncResponse response ) {
executor . execute ( new
new Runnable () {
public void
void run () {
Report report = generateYTDReportFor ( product );
response . resume ( report );
protected Report generateYTDReportFor ( String product ) {
Search WWH ::

Custom Search