• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

ThreadPoolTaskScheduler doesn't works asynchronously.

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • 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: 25956
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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