You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by sara <sa...@yahoo.co.in> on 2014/10/04 18:30:57 UTC
problem with exchange.getProperty in multi threaded environment
Hi
I put in 3 objects with unique UUIds for 3 different threads in the camel
exchange using exchange.setProperty(string,obj). When i retrieve the objects
using exchange.getProperty('key') method i am seeing the objects are
returned with one of them duplicated.So i get 2 Uuids as same.It happens
sporadically.I am using camel-core maven version 2.13.2.
Any help is appreciated.
--
View this message in context: http://camel.465427.n5.nabble.com/problem-with-exchange-getProperty-in-multi-threaded-environment-tp5757354.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: problem with exchange.getProperty in multi threaded environment
Posted by sara <sa...@yahoo.co.in>.
Hi Charles
My route is pretty simple.
<route id="SubmitRoute">
<from uri="direct:Submit" />
<to uri="SaveProcessor" />
</route>
So what the SaveProcessor does is it takes hibernate DataObject from the
camel exchange that we want to save to the DB. Now say there are 3 different
threads sending 3 different DO objects (each has a unique primary key- an
UUID) to the saveProcessor. Now in the saveProcessor when I get the
DataObjects from the exchange I expect those to be same as what was
originally sent, but I see one DO is getting repeated (so the same primary
key is duplicated for couple of different threads) meaning i get only 2 ids
3rd one is lost. This behavior is causing hibernate exceptions as 2
different threads operate on same row in table in the same hibernate
session.This happens sporadically.
Let me give an example here
@Autowired
private CamelContext camelContext;
@Test(enabled = true,invocationCount=3,threadPoolSize=3)
public void testCamelContext(){
Exchange exchange = new DefaultExchange(camelContext);
System.out.println("thread id :" + Thread.currentThread().getId());
exchange.setProperty(CamelConstants.ABC_DO, abcDO);//setting the DO to
save
callSaveProcessor(exchange);//calling the saveProcessor this internally
calls the route.
}
private void callSaveProcessor (Exchange exchange) {
AbcDO abc = exchange.getProperty(CamelConstants.ABC_DO,AbcDO.class);
System.out.println("in getting back the property"+abc.getId());//you get
duplicate primary //keys here.
}
Please let me know.
--
View this message in context: http://camel.465427.n5.nabble.com/problem-with-exchange-getProperty-in-multi-threaded-environment-tp5757354p5757368.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: problem with exchange.getProperty in multi threaded environment
Posted by Charles Moulliard <ch...@gmail.com>.
Hi Sara,
Can you elaborate please a little bit more what you are doing ? What is
your camel route definition, ... ?
Regards,
On Sat, Oct 4, 2014 at 6:30 PM, sara <sa...@yahoo.co.in> wrote:
> Hi
>
> I put in 3 objects with unique UUIds for 3 different threads in the camel
> exchange using exchange.setProperty(string,obj). When i retrieve the
> objects
> using exchange.getProperty('key') method i am seeing the objects are
> returned with one of them duplicated.So i get 2 Uuids as same.It happens
> sporadically.I am using camel-core maven version 2.13.2.
>
> Any help is appreciated.
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/problem-with-exchange-getProperty-in-multi-threaded-environment-tp5757354.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog : http://cmoulliard.github.io