users@grizzly.java.net

Re: How can my application benefit from non-blocking http server like Grizzly?

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Mon, 20 Oct 2008 14:18:37 -0700

Salut,

Ken--_at_newsgroupstats.hk wrote:
> Threads in webapps are always blocked by JDBC calls (or RMI calls) and there
> isn't exist a non blocking JDBC api.
>
> Any solution if I want to build a threadless webapps with glassfish with so
> many jdbc or rmi calls?

Yes, you can either use Grizzly ARP (Asynchronous Request Processing)[1]
or Grizzly Comet[2]. In short, Grizzly AsyncFIlter[3] can be used to
suspend a connection when a JDBC connection pool is empty, and resume it
only when it get available. Are you using a Grizzly extension or Grizzly
in GlassFish right now?

Thanks

-- Jeanfrancois

[1]http://weblogs.java.net/blog/jfarcand/archive/2008/07/extending_the_g.html
[2]http://weblogs.java.net/blog/jfarcand/archive/2006/07/the_grizzly_com.html
[3]https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/arp/AsyncFilter.html


>
>
> Ken--_at_newsgroupstats.hk wrote:
>> Thanks for your quick response.
>>
>> I thought comet is something like ajax. I will firstly try your gmail
>> example.
>>
>> Regards,
>> Ken
>>
>>
>>
>> Jeanfrancois Arcand-2 wrote:
>>> Salut,
>>>
>>> Ken--_at_newsgroupstats.hk wrote:
>>>> In real situation, a thread for serving web request may be blocked (or
>>>> time-waiting?) by something like waiting db enquiry result or waiting
>>>> remote
>>>> process to response (like rmi?). In non-blocking http server like
>>>> Grizzly,
>>>> will the blocked thread be availabled for other web request(s)?
>>> By default, the thread will be blocked. But we have a Grizzly extension
>>> called Grizzly Asynchronous Request Processing[1] that exactly allow you
>>> to do what want, e.g. free threads from blocking on resources. I've gave
>>> an example in [2], and our Comet[4] support is based on top of Grizzly
>>> ARP. I suspect Comet is what you need to look at (Read [4] first IMO)
>>>
>>>
>>>> The stress test result (pages / second) for the following JSP in
>>>> Glassfish
>>>> V2 is the same as Tomcat
>>>> <!--test_sleep.jsp-->
>>>> <%Thread.sleep(100L);%>
>>>> <!--end test_sleep.jsp-->
>>>>
>>>> How about this one?
>>>> <!--test_block.jsp-->
>>>> <%
>>>> ArrayBlockingQueue<Result> arrayBlockingQueue = new
>>>> ArrayBlockingQueue(1);
>>>>
>>>> //ask for result, the result will be stored in the queue by another
>>>> thread
>>>> RemoteProcess.askForResult(arrayBlockingQueue);
>>>>
>>>> Result result = null;
>>>> try {
>>>> // waiting result for 10 seconds, the thread for running this request
>>>> will
>>>> be blocked up to 10 seconds
>>>> result = arrayBlockingQueue.poll(10, TimeUnit.SECOND);
>>>> } catch (Exception e) {
>>>> }
>>>> if (result == null) System.out.println("Time out...");
>>>> %>
>>>> <!--end test_block.jsp-->
>>>>
>>>> How to write my web application so that I can fully make use your thread
>>>> pool?
>>> Yes that's clear. Take a look at the AsyncFilter interface[3] or you
>>> might want to uses Comet directly[4] (based on you example above, I
>>> Strongly recommend you take a look at Comet). Just take a quick look and
>>> let me know if that help or if you need more information.
>>>
>>>
>>> Hope you understand my question.
>>>
>>> Pretty clear.
>>>
>>> Thanks!
>>>
>>> --Jeanfrancois
>>>
>>> [1]http://weblogs.java.net/blog/jfarcand/archive/2006/02/grizzly_part_ii.html
>>> [2]http://weblogs.java.net/blog/jfarcand/archive/2008/07/extending_the_g.html
>>> [3]https://grizzly.dev.java.net/nonav/apidocs/com/sun/grizzly/arp/AsyncFilter.html
>>> [4]
>>> http://weblogs.java.net/blog/jfarcand/archive/2006/07/the_grizzly_com.html
>>>
>>>
>>>> Regards,
>>>> Ken
>>>>
>>>>
>>>>
>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_grizzly.dev.java.net
>>> For additional commands, e-mail: users-help_at_grizzly.dev.java.net
>>>
>>>
>>>
>>
>