You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Narsi Reddy Nallamilli <na...@gmail.com> on 2021/03/10 13:06:16 UTC

Update thread name of threadpool before executing a task

Hi,

I have a executorservice build from threadpoolbuilder.

public ExecutorService jobThreadPool() throws Exception {
    return new ThreadPoolBuilder(getContext()).poolSize(50).maxPoolSize(500).keepAliveTime(180).build("jobThread");
}

I would like to set thread before executing the task, just like as shown

in example which is not recommended. How can we do it correctly? (like
in https://stackoverflow.com/questions/8523453/with-threadpoolexecutor-how-to-get-the-name-of-the-thread-running-in-the-thread)

jobThreadPool.execute(() -> {
//eg. Thread.getCurrentThread().setName("abc");
});

Re: Update thread name of threadpool before executing a task

Posted by Claus Ibsen <cl...@gmail.com>.
On Thu, Mar 11, 2021 at 5:20 PM Narsi Reddy Nallamilli
<na...@gmail.com> wrote:
>
> Hi,
>
> I want to be able to associate each runnable job id to thread so that I can
> associate that threads activity with that thread.
>
> Is the #counter in camel default thread pattern incremented every time a
> thread is used from the pool ?
>

No when a thread is created

> On Wed, Mar 10, 2021 at 11:37 PM Claus Ibsen <cl...@gmail.com> wrote:
>
> > Hi
> >
> > You can plugin your own thread pool factory where you can control how
> > thread pools (ExecutorService) are created and how these thread pools
> > create threads,
> > where you can do the before / after thread thingy.
> >
> > However what is your use-case for doing this?
> >
> >
> >
> > On Wed, Mar 10, 2021 at 2:06 PM Narsi Reddy Nallamilli
> > <na...@gmail.com> wrote:
> > >
> > > Hi,
> > >
> > > I have a executorservice build from threadpoolbuilder.
> > >
> > > public ExecutorService jobThreadPool() throws Exception {
> > >     return new
> > ThreadPoolBuilder(getContext()).poolSize(50).maxPoolSize(500).keepAliveTime(180).build("jobThread");
> > > }
> > >
> > > I would like to set thread before executing the task, just like as shown
> > >
> > > in example which is not recommended. How can we do it correctly? (like
> > > in
> > https://stackoverflow.com/questions/8523453/with-threadpoolexecutor-how-to-get-the-name-of-the-thread-running-in-the-thread
> > )
> > >
> > > jobThreadPool.execute(() -> {
> > > //eg. Thread.getCurrentThread().setName("abc");
> > > });
> >
> >
> >
> > --
> > Claus Ibsen
> > -----------------
> > http://davsclaus.com @davsclaus
> > Camel in Action 2: https://www.manning.com/ibsen2
> >



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2

Re: Update thread name of threadpool before executing a task

Posted by Narsi Reddy Nallamilli <na...@gmail.com>.
Hi,

I want to be able to associate each runnable job id to thread so that I can
associate that threads activity with that thread.

Is the #counter in camel default thread pattern incremented every time a
thread is used from the pool ?

On Wed, Mar 10, 2021 at 11:37 PM Claus Ibsen <cl...@gmail.com> wrote:

> Hi
>
> You can plugin your own thread pool factory where you can control how
> thread pools (ExecutorService) are created and how these thread pools
> create threads,
> where you can do the before / after thread thingy.
>
> However what is your use-case for doing this?
>
>
>
> On Wed, Mar 10, 2021 at 2:06 PM Narsi Reddy Nallamilli
> <na...@gmail.com> wrote:
> >
> > Hi,
> >
> > I have a executorservice build from threadpoolbuilder.
> >
> > public ExecutorService jobThreadPool() throws Exception {
> >     return new
> ThreadPoolBuilder(getContext()).poolSize(50).maxPoolSize(500).keepAliveTime(180).build("jobThread");
> > }
> >
> > I would like to set thread before executing the task, just like as shown
> >
> > in example which is not recommended. How can we do it correctly? (like
> > in
> https://stackoverflow.com/questions/8523453/with-threadpoolexecutor-how-to-get-the-name-of-the-thread-running-in-the-thread
> )
> >
> > jobThreadPool.execute(() -> {
> > //eg. Thread.getCurrentThread().setName("abc");
> > });
>
>
>
> --
> Claus Ibsen
> -----------------
> http://davsclaus.com @davsclaus
> Camel in Action 2: https://www.manning.com/ibsen2
>

Re: Update thread name of threadpool before executing a task

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You can plugin your own thread pool factory where you can control how
thread pools (ExecutorService) are created and how these thread pools
create threads,
where you can do the before / after thread thingy.

However what is your use-case for doing this?



On Wed, Mar 10, 2021 at 2:06 PM Narsi Reddy Nallamilli
<na...@gmail.com> wrote:
>
> Hi,
>
> I have a executorservice build from threadpoolbuilder.
>
> public ExecutorService jobThreadPool() throws Exception {
>     return new ThreadPoolBuilder(getContext()).poolSize(50).maxPoolSize(500).keepAliveTime(180).build("jobThread");
> }
>
> I would like to set thread before executing the task, just like as shown
>
> in example which is not recommended. How can we do it correctly? (like
> in https://stackoverflow.com/questions/8523453/with-threadpoolexecutor-how-to-get-the-name-of-the-thread-running-in-the-thread)
>
> jobThreadPool.execute(() -> {
> //eg. Thread.getCurrentThread().setName("abc");
> });



-- 
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2