You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paulo Silveira <pa...@gmail.com> on 2010/08/29 07:51:38 UTC

async response being commited after flush in 7.0.x?

Hello

I am starting async requests inside a  asyncSupported=true servlet.
After that, sometimes an event occurs and I need to dispatch a small
message to each client. For this purpose I use a executor that will
send this message to each client in an obvious way:

	for (final AsyncContext ctx : clients) {							
		executors.execute(new Runnable() {
			public void run() {
				try {
						if (ctx.getResponse().isCommitted()) {
								System.out.println("wow! why?");
								return;
						}
										
						PrintWriter writer = ctx.getResponse().getWriter();
						writer	.println(message);
						writer.flush();

						} catch (IOException e) {
							e.printStackTrace();
						}
					}

				});	
		}

After the firs message being sent for the client,
getResponse().isCommited is true. If I try to send the second message,
I will get an EOF exception.

Thanks
--
Paulo Silveira
Caelum | Ensino e Inovação
www.caelum.com.br
www.arquiteturajava.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: async response being commited after flush in 7.0.x?

Posted by Paulo Silveira - Caelum <pa...@caelum.com.br>.
Hi Mark

Thanks, I waas checking if the response was comitteds, but I had to
check if the print writer was closed (which is not, although the
headers were sent, of course)

Paulo


--
Paulo Silveira
Caelum | Ensino e Inovação
www.caelum.com.br
www.arquiteturajava.com.br



On Sun, Aug 29, 2010 at 12:24 PM, Mark Thomas <ma...@apache.org> wrote:
> On 29/08/2010 13:18, Paulo Silveira - Caelum wrote:
>> 7.0.2.
>
> The response being committed is expected. Once the headers are sent to
> the client then the response is committed - although it may not be complete.
>
> How long is the gap between the flush and the next write? If it is
> longer than the async timeout (defaults to the connection timeout) then
> Tomcat will automatically complete the request.
>
> Mark
>
>>
>> On Aug 29, 2010 4:34 AM, "Pid *" <pi...@pidster.com> wrote:
>>> On 29 Aug 2010, at 06:51, Paulo Silveira <pa...@gmail.com> wrote:
>>>
>>>> Hello
>>>>
>>>> I am starting async requests inside a asyncSupported=true servlet.
>>>> After that, sometimes an event occurs and I need to dispatch a small
>>>> message to each client. For this purpose I use a executor that will
>>>> send this message to each client in an obvious way:
>>>>
>>>> for (final AsyncContext ctx : clients) {
>>>> executors.execute(new Runnable() {
>>>> public void run() {
>>>> try {
>>>> if (ctx.getResponse().isCommitted()) {
>>>> System.out.println("wow! why?");
>>>> return;
>>>> }
>>>>
>>>> PrintWriter writer = ctx.getResponse().getWriter();
>>>> writer .println(message);
>>>> writer.flush();
>>>>
>>>> } catch (IOException e) {
>>>> e.printStackTrace();
>>>> }
>>>> }
>>>>
>>>> });
>>>> }
>>>>
>>>> After the firs message being sent for the client,
>>>> getResponse().isCommited is true. If I try to send the second message,
>>>> I will get an EOF exception.
>>>
>>> Exactly which version of Tomcat 7.0.x?
>>>
>>>
>>> p
>>>
>>>
>>>>
>>>> Thanks
>>>> --
>>>> Paulo Silveira
>>>> Caelum | Ensino e Inovação
>>>> www.caelum.com.br
>>>> www.arquiteturajava.com.br
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: async response being commited after flush in 7.0.x?

Posted by Mark Thomas <ma...@apache.org>.
On 29/08/2010 13:18, Paulo Silveira - Caelum wrote:
> 7.0.2.

The response being committed is expected. Once the headers are sent to
the client then the response is committed - although it may not be complete.

How long is the gap between the flush and the next write? If it is
longer than the async timeout (defaults to the connection timeout) then
Tomcat will automatically complete the request.

Mark

> 
> On Aug 29, 2010 4:34 AM, "Pid *" <pi...@pidster.com> wrote:
>> On 29 Aug 2010, at 06:51, Paulo Silveira <pa...@gmail.com> wrote:
>>
>>> Hello
>>>
>>> I am starting async requests inside a asyncSupported=true servlet.
>>> After that, sometimes an event occurs and I need to dispatch a small
>>> message to each client. For this purpose I use a executor that will
>>> send this message to each client in an obvious way:
>>>
>>> for (final AsyncContext ctx : clients) {
>>> executors.execute(new Runnable() {
>>> public void run() {
>>> try {
>>> if (ctx.getResponse().isCommitted()) {
>>> System.out.println("wow! why?");
>>> return;
>>> }
>>>
>>> PrintWriter writer = ctx.getResponse().getWriter();
>>> writer .println(message);
>>> writer.flush();
>>>
>>> } catch (IOException e) {
>>> e.printStackTrace();
>>> }
>>> }
>>>
>>> });
>>> }
>>>
>>> After the firs message being sent for the client,
>>> getResponse().isCommited is true. If I try to send the second message,
>>> I will get an EOF exception.
>>
>> Exactly which version of Tomcat 7.0.x?
>>
>>
>> p
>>
>>
>>>
>>> Thanks
>>> --
>>> Paulo Silveira
>>> Caelum | Ensino e Inovação
>>> www.caelum.com.br
>>> www.arquiteturajava.com.br
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: async response being commited after flush in 7.0.x?

Posted by Paulo Silveira - Caelum <pa...@caelum.com.br>.
7.0.2.

On Aug 29, 2010 4:34 AM, "Pid *" <pi...@pidster.com> wrote:
> On 29 Aug 2010, at 06:51, Paulo Silveira <pa...@gmail.com> wrote:
>
>> Hello
>>
>> I am starting async requests inside a asyncSupported=true servlet.
>> After that, sometimes an event occurs and I need to dispatch a small
>> message to each client. For this purpose I use a executor that will
>> send this message to each client in an obvious way:
>>
>> for (final AsyncContext ctx : clients) {
>> executors.execute(new Runnable() {
>> public void run() {
>> try {
>> if (ctx.getResponse().isCommitted()) {
>> System.out.println("wow! why?");
>> return;
>> }
>>
>> PrintWriter writer = ctx.getResponse().getWriter();
>> writer .println(message);
>> writer.flush();
>>
>> } catch (IOException e) {
>> e.printStackTrace();
>> }
>> }
>>
>> });
>> }
>>
>> After the firs message being sent for the client,
>> getResponse().isCommited is true. If I try to send the second message,
>> I will get an EOF exception.
>
> Exactly which version of Tomcat 7.0.x?
>
>
> p
>
>
>>
>> Thanks
>> --
>> Paulo Silveira
>> Caelum | Ensino e Inovação
>> www.caelum.com.br
>> www.arquiteturajava.com.br
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

Re: async response being commited after flush in 7.0.x?

Posted by Pid * <pi...@pidster.com>.
On 29 Aug 2010, at 06:51, Paulo Silveira <pa...@gmail.com> wrote:

> Hello
>
> I am starting async requests inside a  asyncSupported=true servlet.
> After that, sometimes an event occurs and I need to dispatch a small
> message to each client. For this purpose I use a executor that will
> send this message to each client in an obvious way:
>
>    for (final AsyncContext ctx : clients) {
>        executors.execute(new Runnable() {
>            public void run() {
>                try {
>                        if (ctx.getResponse().isCommitted()) {
>                                System.out.println("wow! why?");
>                                return;
>                        }
>
>                        PrintWriter writer = ctx.getResponse().getWriter();
>                        writer    .println(message);
>                        writer.flush();
>
>                        } catch (IOException e) {
>                            e.printStackTrace();
>                        }
>                    }
>
>                });
>        }
>
> After the firs message being sent for the client,
> getResponse().isCommited is true. If I try to send the second message,
> I will get an EOF exception.

Exactly which version of Tomcat 7.0.x?


p


>
> Thanks
> --
> Paulo Silveira
> Caelum | Ensino e Inovação
> www.caelum.com.br
> www.arquiteturajava.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org