• Post Reply Bookmark Topic Watch Topic
  • New Topic

AtomicBoolean to prevent multiple invocations  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to implement a service that accepts subscription requests from many threads.

Since the state "subscribed" is a global condition; only one request should be entertain.



Basically the implementation of subscribe would look like this:

Am I going the right direction with this ?

Regards

Pho
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I going the right direction with this ?


If you are asking if this is thread safe, and will work as you want, the answer is yes. If you are asking this as a design issue, then we don't have enough info.

Henry
 
Ray Hsieh
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pho Tek:
I want to implement a service that accepts subscription requests from many threads.

Since the state "subscribed" is a global condition; only one request should be entertain.

...



Sounds to me like a wait/notify scenario. Do the threads have to queue or any of them can get processed as long as it's one at a time? How many threads are processing subscription? etc. etc. Like Henry said, we really don't have enough info about what you're trying ot do to tell whether you're going in the right direction or not with this one.
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The SubscriptionService is implementing a SSO (single sign on) service for many concurrent clients. If one client has managed to subscribe, other clients should not need to re-subscribe.

The logic for a client:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!