I am looking for something similar as Queue type in Python in Groovy language.
In python Queues let to exchange information between threads and take care about all locking problems/challenges. So one thread can simply add a task to queue
while True:
if self.task_ready():
task = self.get_task()
self.queue.put(task)
print 'Task %s added to queue' % (task.name)
and worker threads can:
while True:
self.queue.get() # this is read blocking action
self.proces_task(task)
is there a way to do it in such easy way in Groovy?
You could use a Queue.
Java has LinkedBlockingQueue in its java.util.concurrent package which you can just use from Groovy. There’s an article over here on JavaLobby that discusses these structures (obviously from a Java perspective, but you can use the all from Groovy)