• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

ThreadPoolTaskScheduler doesn't works asynchronously.

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am using Spring-BOOT
I am trying to execute some task in the same time.

1. I defined a scheduler
2. set pool-size to 10.
3. schedule some tasks (for loop ) with crone expression for every 1 second.

I expected the scheduler to execute 10 task with different threads asynchronously.
But  it executes each time with only one thread.










the output is :
jobScheduler-1
jobScheduler-1
jobScheduler-1
jobScheduler-1
jobScheduler-1
jobScheduler-1

It is like using only one thread, but it has 10 threads in the pool.


i expected to be asyncronically :
jobScheduler-1
jobScheduler-2
jobScheduler-3
jobScheduler-4
jobScheduler-1
jobScheduler-3
jobScheduler-1
...

What is wrong?

Thanks
Itamar.
 
Marshal
Posts: 27540
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps I'm misunderstanding your code, but it seems to me that you are only scheduling one task, and therefore the pool only needs to use one thread for that.

You also have some code which prints the thread name 41 times, and I have no idea why you're doing that, but you should expect to see the thread name printed 41 times. Which is what you are seeing.
reply
    Bookmark Topic Watch Topic
  • New Topic