You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Angelo C." <an...@gmail.com> on 2012/06/13 14:56:28 UTC

non blocking code in T5?

hi,

Got this situation, for every request, I need to call a function of a
service, if I understand it, this is a 'blocking' code, the flow will
continue only when the function returns, solution that I can think of is,
create a thread, and let it run, but considering so many requests can happen
in the same time, this might be quite costly, any better suggestion? Thanks,

Angelo

--
View this message in context: http://tapestry.1045711.n5.nabble.com/non-blocking-code-in-T5-tp5713836.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: non blocking code in T5?

Posted by Lance Java <la...@googlemail.com>.
This is not a tapestry question but is a general java concurrency question

1. If you do not use synchronized (or one of the java.util.concurrent.*
classes) then multiple threads can enter the method simultaneously.

2. If your method only reads from "shared" immutable fields, you do not need
to worry about synchronizing anything.

3. If your method reads from / writes to a "shared" mutable field, you must
synchronize these blocks of code somehow either by using the "synchronized"
keyword or by using one of the java.util.concurrent.* libraries.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/non-blocking-code-in-T5-tp5713836p5713837.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: non blocking code in T5?

Posted by Cezary Biernacki <ce...@gmail.com>.
However, it is worth to mention that Tapestry-IOC provides ParallelExecutor
service that encapsulates Java's ThreadPoolExecutor.

Cezary


On Wed, Jun 13, 2012 at 5:53 PM, Thiago H de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Wed, 13 Jun 2012 12:13:52 -0300, Angelo C. <an...@gmail.com>
> wrote:
>
>  that should work, any sample code applicable to t5?
>>
>
> As Lance said before, this is completely independent of Tapestry, any
> sample code you'll find is applicable. This shouldn't have even be posted
> in this mailing list, as it's completely off-topic.
>
> --
> Thiago H. de Paula Figueiredo
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: non blocking code in T5?

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 13 Jun 2012 12:13:52 -0300, Angelo C. <an...@gmail.com>  
wrote:

> that should work, any sample code applicable to t5?

As Lance said before, this is completely independent of Tapestry, any  
sample code you'll find is applicable. This shouldn't have even be posted  
in this mailing list, as it's completely off-topic.

-- 
Thiago H. de Paula Figueiredo

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


Re: non blocking code in T5?

Posted by "Angelo C." <an...@gmail.com>.
that should work, any sample code applicable to t5?


Muhammad Gelbana wrote
> 
> I've been using Java's executor service lately and it's very neat.
> http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html
> 
> 
> It's just that I don't think it can guarantee a new thread for each
> request
> in case you are using per-thread scope services.
> 
> On Wed, Jun 13, 2012 at 4:37 PM, Dmitry Gusev &lt;dmitry.gusev@&gt;wrote:
> 
>> You need Java EE if you want to use Java Message Service, or you can use
>> Apache TomEE which implements JMS
>> (http://tomee.apache.org/tomcat-jms.html
>> )
>> -- I haven't used TomEE though.
>>
>> Or you can implement your own queue (based on ArrayBlockingQueue, for
>> instance) with consumer thread(s) which you should start manually.
>>
>> Both approaches have their pros and cons, though.
>>
>> On Wed, Jun 13, 2012 at 6:04 PM, Angelo C. &lt;angelochen960@&gt;
>> wrote:
>>
>> > no, i don't need the response from the method, MS/JMS is new to me, can
>> it
>> > be
>> > used even I 'm not using Java EE?
>> >
>> >
>> > Dmitry Gusev wrote
>> > >
>> > > Do you plan to consume method's response in the same request?
>> > >
>> > > If not, some sort of MQ/JMS may be an option--just put your message
>> there
>> > > and return.
>> > > The message itself will be processed in separate thread with MQ
>> handler
>> > > (Message-Driven Bean in case of Java EE).
>> > >
>> > > Dmitry Gusev
>> > >
>> > > AnjLab Team
>> > > http://anjlab.com
>> > >
>> >
>> >
>> > --
>> > View this message in context:
>> >
>> http://tapestry.1045711.n5.nabble.com/non-blocking-code-in-T5-tp5713836p5713841.html
>> > Sent from the Tapestry - User mailing list archive at Nabble.com.
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@.apache
>> > For additional commands, e-mail: users-help@.apache
>> >
>> >
>>
>>
>> --
>> Dmitry Gusev
>>
>> AnjLab Team
>> http://anjlab.com
>>
> 
> 
> 
> -- 
> *Regards,*
> *Muhammad Gelbana
> Java Developer*
> 


--
View this message in context: http://tapestry.1045711.n5.nabble.com/non-blocking-code-in-T5-tp5713836p5713846.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: non blocking code in T5?

Posted by Muhammad Gelbana <m....@gmail.com>.
I've been using Java's executor service lately and it's very neat.
http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html


It's just that I don't think it can guarantee a new thread for each request
in case you are using per-thread scope services.

On Wed, Jun 13, 2012 at 4:37 PM, Dmitry Gusev <dm...@gmail.com>wrote:

> You need Java EE if you want to use Java Message Service, or you can use
> Apache TomEE which implements JMS (http://tomee.apache.org/tomcat-jms.html
> )
> -- I haven't used TomEE though.
>
> Or you can implement your own queue (based on ArrayBlockingQueue, for
> instance) with consumer thread(s) which you should start manually.
>
> Both approaches have their pros and cons, though.
>
> On Wed, Jun 13, 2012 at 6:04 PM, Angelo C. <an...@gmail.com>
> wrote:
>
> > no, i don't need the response from the method, MS/JMS is new to me, can
> it
> > be
> > used even I 'm not using Java EE?
> >
> >
> > Dmitry Gusev wrote
> > >
> > > Do you plan to consume method's response in the same request?
> > >
> > > If not, some sort of MQ/JMS may be an option--just put your message
> there
> > > and return.
> > > The message itself will be processed in separate thread with MQ handler
> > > (Message-Driven Bean in case of Java EE).
> > >
> > > Dmitry Gusev
> > >
> > > AnjLab Team
> > > http://anjlab.com
> > >
> >
> >
> > --
> > View this message in context:
> >
> http://tapestry.1045711.n5.nabble.com/non-blocking-code-in-T5-tp5713836p5713841.html
> > Sent from the Tapestry - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
> --
> Dmitry Gusev
>
> AnjLab Team
> http://anjlab.com
>



-- 
*Regards,*
*Muhammad Gelbana
Java Developer*

Re: non blocking code in T5?

Posted by Andreas Fink <fi...@googlemail.com>.
If you do not want to go down the JEE route, try Hazelcast. I have had good experiences with it in the past.
Apart from shared maps, it also provides topics and queues like JMS.

The most basic setup can look like this:

public HazelcastInstance buildHazelcastInstance() {
    final Config cfg = new InMemoryXmlConfig("<hazelcast></hazelcast>");
    cfg.setProperty("hazelcast.logging.type", "slf4j");
    cfg.setProperty("hazelcast.rest.enabled", "false");
		
    return Hazelcast.init(cfg);
}

If clustering is not needed or you think this dependency is way too huge, try building something on top of google-guava's event bus: http://docs.guava-libraries.googlecode.com/git-history/v12.0/javadoc/com/google/common/eventbus/package-summary.html

cheers,
andi.

On Jun 13, 2012, at 16:37 , Dmitry Gusev wrote:

> You need Java EE if you want to use Java Message Service, or you can use
> Apache TomEE which implements JMS (http://tomee.apache.org/tomcat-jms.html)
> -- I haven't used TomEE though.
> 
> Or you can implement your own queue (based on ArrayBlockingQueue, for
> instance) with consumer thread(s) which you should start manually.
> 
> Both approaches have their pros and cons, though.
> 
> On Wed, Jun 13, 2012 at 6:04 PM, Angelo C. <an...@gmail.com> wrote:
> 
>> no, i don't need the response from the method, MS/JMS is new to me, can it
>> be
>> used even I 'm not using Java EE?
>> 
>> 
>> Dmitry Gusev wrote
>>> 
>>> Do you plan to consume method's response in the same request?
>>> 
>>> If not, some sort of MQ/JMS may be an option--just put your message there
>>> and return.
>>> The message itself will be processed in separate thread with MQ handler
>>> (Message-Driven Bean in case of Java EE).
>>> 
>>> Dmitry Gusev
>>> 
>>> AnjLab Team
>>> http://anjlab.com
>>> 
>> 
>> 
>> --
>> View this message in context:
>> http://tapestry.1045711.n5.nabble.com/non-blocking-code-in-T5-tp5713836p5713841.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 
> 
> 
> -- 
> Dmitry Gusev
> 
> AnjLab Team
> http://anjlab.com


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


Re: non blocking code in T5?

Posted by Dmitry Gusev <dm...@gmail.com>.
You need Java EE if you want to use Java Message Service, or you can use
Apache TomEE which implements JMS (http://tomee.apache.org/tomcat-jms.html)
-- I haven't used TomEE though.

Or you can implement your own queue (based on ArrayBlockingQueue, for
instance) with consumer thread(s) which you should start manually.

Both approaches have their pros and cons, though.

On Wed, Jun 13, 2012 at 6:04 PM, Angelo C. <an...@gmail.com> wrote:

> no, i don't need the response from the method, MS/JMS is new to me, can it
> be
> used even I 'm not using Java EE?
>
>
> Dmitry Gusev wrote
> >
> > Do you plan to consume method's response in the same request?
> >
> > If not, some sort of MQ/JMS may be an option--just put your message there
> > and return.
> > The message itself will be processed in separate thread with MQ handler
> > (Message-Driven Bean in case of Java EE).
> >
> > Dmitry Gusev
> >
> > AnjLab Team
> > http://anjlab.com
> >
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/non-blocking-code-in-T5-tp5713836p5713841.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com

Re: non blocking code in T5?

Posted by "Angelo C." <an...@gmail.com>.
no, i don't need the response from the method, MS/JMS is new to me, can it be
used even I 'm not using Java EE?


Dmitry Gusev wrote
> 
> Do you plan to consume method's response in the same request?
> 
> If not, some sort of MQ/JMS may be an option--just put your message there
> and return.
> The message itself will be processed in separate thread with MQ handler
> (Message-Driven Bean in case of Java EE).
> 
> Dmitry Gusev
> 
> AnjLab Team
> http://anjlab.com
> 


--
View this message in context: http://tapestry.1045711.n5.nabble.com/non-blocking-code-in-T5-tp5713836p5713841.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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


Re: non blocking code in T5?

Posted by Dmitry Gusev <dm...@gmail.com>.
Do you plan to consume method's response in the same request?

If not, some sort of MQ/JMS may be an option--just put your message there
and return.
The message itself will be processed in separate thread with MQ handler
(Message-Driven Bean in case of Java EE).

On Wed, Jun 13, 2012 at 4:56 PM, Angelo C. <an...@gmail.com> wrote:

> hi,
>
> Got this situation, for every request, I need to call a function of a
> service, if I understand it, this is a 'blocking' code, the flow will
> continue only when the function returns, solution that I can think of is,
> create a thread, and let it run, but considering so many requests can
> happen
> in the same time, this might be quite costly, any better suggestion?
> Thanks,
>
> Angelo
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/non-blocking-code-in-T5-tp5713836.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Dmitry Gusev

AnjLab Team
http://anjlab.com