• Post Reply Bookmark Topic Watch Topic
  • New Topic

Is this design ok ?  RSS feed

 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am basically writing a consumer app that connects to a server and polls it for data. Since the internet link between the consumer and producer is unreliable with packet losses and slow ping times, I introduce a design that allows for eternal reconnections.



Is this a reasonable & robust design ?
I a bit worried about a possible race condition in the consecutive calls to begin and join. Would it ever happen that the thread is not running yet and I call a join ?

Regards,

Pho
 
Henry Wong
author
Sheriff
Posts: 23282
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a reasonable & robust design ?


I am assuming that this is just an example -- as your consumer and server are not connected via a network. It is just a thread in the same JVM.

I a bit worried about a possible race condition in the consecutive calls to begin and join. Would it ever happen that the thread is not running yet and I call a join ?


Once you return from the start() method, you can call join() on it to wait for it's completion. It will be considered alive once start() returns, although it may not be actually running yet.

Henry
 
Pho Tek
Ranch Hand
Posts: 782
Chrome Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry,

I didn't actually show the actual code that connects the Consumer and Producer but the IPC involved is a queue.

Once you return from the start() method, you can call join() on it to wait for it's completion. It will be considered alive once start() returns, although it may not be actually running yet.

Thanks for the clarification. That was the worrying point for me.

Regards,

Pho
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!