You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Deepthi <de...@gmail.com> on 2012/06/06 18:09:06 UTC

Generate a thread for each db record

Hi,

In my route my source is retrieving records from a table by executing
following query:
select * from tablename
and I would like to generate a thread for each record to process the records
simultaneously.
How can I achieve this in camel spring 2.8.0?

If i use a timer as my source and give the logic in the bean to retrieve the
records, can i generate 1 thread for each record in the bean? Else what is
the way to implement it?

Claus - As you replied in previous thread, I am unable to understand how
splitter can be used as I cannot give sql query as my source.

Thanks,
Deepthi

--
View this message in context: http://camel.465427.n5.nabble.com/Generate-a-thread-for-each-db-record-tp5714079.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Generate a thread for each db record

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jun 6, 2012 at 6:26 PM, James Carman <ja...@carmanconsulting.com> wrote:
> I was just saying don't generate a new thread for each record, use a pool.
>

Yes I agree a pool is better and the splitter uses that already if
enabling concurrency,
either with the parallel or executorService ref options.




>
> On Wed, Jun 6, 2012 at 12:16 PM, Claus Ibsen <cl...@gmail.com> wrote:
>
>> On Wed, Jun 6, 2012 at 6:11 PM, James Carman <ja...@carmanconsulting.com>
>> wrote:
>> > You'd be better off using a thread pool.  Try using the "threads" DSL
>> > construct.
>> >
>>
>> That wont help as he want a seperate thread for each record in the SQL
>> result set.
>> So if it returns 53 rows, he want 53 tasks, to be executed by a thread
>> pool.
>>
>> The threads DSL will process a single message containing the 53 rows.
>> So he need to split the rows into individual messages, and hence the
>> splitter EIP
>>
>>
>> > On Wed, Jun 6, 2012 at 12:09 PM, Deepthi <de...@gmail.com> wrote:
>> >
>> >> Hi,
>> >>
>> >> In my route my source is retrieving records from a table by executing
>> >> following query:
>> >> select * from tablename
>> >> and I would like to generate a thread for each record to process the
>> >> records
>> >> simultaneously.
>> >> How can I achieve this in camel spring 2.8.0?
>> >>
>> >> If i use a timer as my source and give the logic in the bean to retrieve
>> >> the
>> >> records, can i generate 1 thread for each record in the bean? Else what
>> is
>> >> the way to implement it?
>> >>
>> >> Claus - As you replied in previous thread, I am unable to understand how
>> >> splitter can be used as I cannot give sql query as my source.
>> >>
>> >> Thanks,
>> >> Deepthi
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://camel.465427.n5.nabble.com/Generate-a-thread-for-each-db-record-tp5714079.html
>> >> Sent from the Camel - Users mailing list archive at Nabble.com.
>> >>
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: cibsen@fusesource.com
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Generate a thread for each db record

Posted by James Carman <ja...@carmanconsulting.com>.
I was just saying don't generate a new thread for each record, use a pool.


On Wed, Jun 6, 2012 at 12:16 PM, Claus Ibsen <cl...@gmail.com> wrote:

> On Wed, Jun 6, 2012 at 6:11 PM, James Carman <ja...@carmanconsulting.com>
> wrote:
> > You'd be better off using a thread pool.  Try using the "threads" DSL
> > construct.
> >
>
> That wont help as he want a seperate thread for each record in the SQL
> result set.
> So if it returns 53 rows, he want 53 tasks, to be executed by a thread
> pool.
>
> The threads DSL will process a single message containing the 53 rows.
> So he need to split the rows into individual messages, and hence the
> splitter EIP
>
>
> > On Wed, Jun 6, 2012 at 12:09 PM, Deepthi <de...@gmail.com> wrote:
> >
> >> Hi,
> >>
> >> In my route my source is retrieving records from a table by executing
> >> following query:
> >> select * from tablename
> >> and I would like to generate a thread for each record to process the
> >> records
> >> simultaneously.
> >> How can I achieve this in camel spring 2.8.0?
> >>
> >> If i use a timer as my source and give the logic in the bean to retrieve
> >> the
> >> records, can i generate 1 thread for each record in the bean? Else what
> is
> >> the way to implement it?
> >>
> >> Claus - As you replied in previous thread, I am unable to understand how
> >> splitter can be used as I cannot give sql query as my source.
> >>
> >> Thanks,
> >> Deepthi
> >>
> >> --
> >> View this message in context:
> >>
> http://camel.465427.n5.nabble.com/Generate-a-thread-for-each-db-record-tp5714079.html
> >> Sent from the Camel - Users mailing list archive at Nabble.com.
> >>
>
>
>
> --
> Claus Ibsen
> -----------------
> FuseSource
> Email: cibsen@fusesource.com
> Web: http://fusesource.com
> Twitter: davsclaus, fusenews
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>

Re: Generate a thread for each db record

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jun 6, 2012 at 6:11 PM, James Carman <ja...@carmanconsulting.com> wrote:
> You'd be better off using a thread pool.  Try using the "threads" DSL
> construct.
>

That wont help as he want a seperate thread for each record in the SQL
result set.
So if it returns 53 rows, he want 53 tasks, to be executed by a thread pool.

The threads DSL will process a single message containing the 53 rows.
So he need to split the rows into individual messages, and hence the
splitter EIP


> On Wed, Jun 6, 2012 at 12:09 PM, Deepthi <de...@gmail.com> wrote:
>
>> Hi,
>>
>> In my route my source is retrieving records from a table by executing
>> following query:
>> select * from tablename
>> and I would like to generate a thread for each record to process the
>> records
>> simultaneously.
>> How can I achieve this in camel spring 2.8.0?
>>
>> If i use a timer as my source and give the logic in the bean to retrieve
>> the
>> records, can i generate 1 thread for each record in the bean? Else what is
>> the way to implement it?
>>
>> Claus - As you replied in previous thread, I am unable to understand how
>> splitter can be used as I cannot give sql query as my source.
>>
>> Thanks,
>> Deepthi
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Generate-a-thread-for-each-db-record-tp5714079.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: Generate a thread for each db record

Posted by James Carman <ja...@carmanconsulting.com>.
You'd be better off using a thread pool.  Try using the "threads" DSL
construct.

On Wed, Jun 6, 2012 at 12:09 PM, Deepthi <de...@gmail.com> wrote:

> Hi,
>
> In my route my source is retrieving records from a table by executing
> following query:
> select * from tablename
> and I would like to generate a thread for each record to process the
> records
> simultaneously.
> How can I achieve this in camel spring 2.8.0?
>
> If i use a timer as my source and give the logic in the bean to retrieve
> the
> records, can i generate 1 thread for each record in the bean? Else what is
> the way to implement it?
>
> Claus - As you replied in previous thread, I am unable to understand how
> splitter can be used as I cannot give sql query as my source.
>
> Thanks,
> Deepthi
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Generate-a-thread-for-each-db-record-tp5714079.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Generate a thread for each db record

Posted by Deepthi <de...@gmail.com>.
Thanks Claus. This works.
I have another question. When I use the split and parallel processing as
true, can i control the number of threads to be processed simultaneously.

If the split EIP doesnt support it, should I use multi-threading?

Thanks,
Deepthi

--
View this message in context: http://camel.465427.n5.nabble.com/Generate-a-thread-for-each-db-record-tp5714079p5714096.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Generate a thread for each db record

Posted by Claus Ibsen <cl...@gmail.com>.
On Wed, Jun 6, 2012 at 6:09 PM, Deepthi <de...@gmail.com> wrote:
> Hi,
>
> In my route my source is retrieving records from a table by executing
> following query:
> select * from tablename
> and I would like to generate a thread for each record to process the records
> simultaneously.
> How can I achieve this in camel spring 2.8.0?
>
> If i use a timer as my source and give the logic in the bean to retrieve the
> records, can i generate 1 thread for each record in the bean? Else what is
> the way to implement it?
>
> Claus - As you replied in previous thread, I am unable to understand how
> splitter can be used as I cannot give sql query as my source.
>

from timer
  to jdbc
  split body (parallel = true)
      to somewhere

Read the eip docs, and try out stuff. Its really best to try out
yourself and get experience.
http://camel.apache.org/splitter

If you got a copy of Camel in Action book, then chapter 8 and 10 talk
about the EIPs and concurrency/threading in much more details.





> Thanks,
> Deepthi
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Generate-a-thread-for-each-db-record-tp5714079.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen