• 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
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Concurrent ExecutorService with partial sequential processing  RSS feed

 
Bartender
Posts: 2184
46
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a ready implementation (JDK, Guava, Apache Commons?) of an ExecutorService that would allow processing of submitted jobs concurrently,
but based on a certain condition (e.g. a job that would change the same user) it would execute those (user) jobs sequentially to each other (it would be still allowed to execute jobs regarding other users concurrently).

 
Saloon Keeper
Posts: 9389
181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need. You can easily do this by yourself by submitting one task per user, with the task itself performing sub-tasks sequentially.
 
Paweł Baczyński
Bartender
Posts: 2184
46
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The point is, at the moment of submitting a task I don't have any information whether there are or will be more tasks that would touch the same user.
 
Stephan van Hulst
Saloon Keeper
Posts: 9389
181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't test it, but it might be what you need:
 
Stephan van Hulst
Saloon Keeper
Posts: 9389
181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An update with test:





Output:

Completed: Task B,0
Completed: Task C,0
Completed: Task A,0
Completed: Task B,1
Completed: Task C,1
Completed: Task A,1
Completed: Task B,2
Completed: Task C,2
Completed: Task A,2
Task A,3 failed with reason: java.lang.Exception: Whatever!
Task A,4 failed with reason: java.lang.Exception: Whatever!
Task A,5 failed with reason: java.lang.Exception: Whatever!
Task A,6 failed with reason: java.lang.Exception: Whatever!
Task A,7 failed with reason: java.lang.Exception: Whatever!
Task A,8 failed with reason: java.lang.Exception: Whatever!
Task A,9 failed with reason: java.lang.Exception: Whatever!
Completed: Task C,3
Completed: Task B,3
Completed: Task B,4
Completed: Task C,4
Completed: Task C,5
Completed: Task B,5
Task B,6 was cancelled.
Task B,7 failed with reason: java.util.concurrent.CancellationException
Task B,8 failed with reason: java.util.concurrent.CancellationException
Task B,9 failed with reason: java.util.concurrent.CancellationException
Completed: Task C,6
Completed: Task C,7
Completed: Task C,8
Completed: Task C,9

 
Paweł Baczyński
Bartender
Posts: 2184
46
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tested it briefly and it seems to works as expected! Thanks!
Too bad I am bound to use JDK 1.7.
But now I get the idea how this can be implemented. Thanks again. Have a cow.
 
Stephan van Hulst
Saloon Keeper
Posts: 9389
181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paweł.

I've tried a few things, but I can't really think of an equally satisfying solution in Java 7. I'll ponder on it a little bit more.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!