blockingqueue

Blocking Queue Take out of Order

狂风中的少年 提交于 2021-01-24 18:43:29
问题 I have a simple blocking queue containing Integers. In a multi thread environment I am taking and adding elements to the the back of the queue. BlockingQueue<Integer> test = new LinkedBlockingQueue<Integer>(); The goal is to have adding in order.. and taking be in the same order as well. On the 5th line of my program output, 3 is somehow at the front of the queue before 2 is, despite it appearing that 2 was added first. All of these were added in a single threaded environment, so I know the

Blocking Queue Take out of Order

最后都变了- 提交于 2021-01-24 18:28:23
问题 I have a simple blocking queue containing Integers. In a multi thread environment I am taking and adding elements to the the back of the queue. BlockingQueue<Integer> test = new LinkedBlockingQueue<Integer>(); The goal is to have adding in order.. and taking be in the same order as well. On the 5th line of my program output, 3 is somehow at the front of the queue before 2 is, despite it appearing that 2 was added first. All of these were added in a single threaded environment, so I know the

Blocking Queue Take out of Order

我的未来我决定 提交于 2021-01-24 18:27:22
问题 I have a simple blocking queue containing Integers. In a multi thread environment I am taking and adding elements to the the back of the queue. BlockingQueue<Integer> test = new LinkedBlockingQueue<Integer>(); The goal is to have adding in order.. and taking be in the same order as well. On the 5th line of my program output, 3 is somehow at the front of the queue before 2 is, despite it appearing that 2 was added first. All of these were added in a single threaded environment, so I know the

Blocking Queue Take out of Order

烂漫一生 提交于 2021-01-24 18:24:52
问题 I have a simple blocking queue containing Integers. In a multi thread environment I am taking and adding elements to the the back of the queue. BlockingQueue<Integer> test = new LinkedBlockingQueue<Integer>(); The goal is to have adding in order.. and taking be in the same order as well. On the 5th line of my program output, 3 is somehow at the front of the queue before 2 is, despite it appearing that 2 was added first. All of these were added in a single threaded environment, so I know the

Java BlockingQueue with batching?

♀尐吖头ヾ 提交于 2020-06-22 09:36:28
问题 I am interested in a data structure identical to the Java BlockingQueue, with the exception that it must be able to batch objects in the queue. In other words, I would like the producer to be able to put objects into the queue, but have the consumer block on take() untill the queue reaches a certain size (the batch size). Then, once the queue has reached the batch size, the producer must block on put() untill the consumer has consumed all of the elements in the queue (in which case the

Java BlockingQueue with batching?

旧城冷巷雨未停 提交于 2020-06-22 09:36:12
问题 I am interested in a data structure identical to the Java BlockingQueue, with the exception that it must be able to batch objects in the queue. In other words, I would like the producer to be able to put objects into the queue, but have the consumer block on take() untill the queue reaches a certain size (the batch size). Then, once the queue has reached the batch size, the producer must block on put() untill the consumer has consumed all of the elements in the queue (in which case the

How to call same method of a different class in multithreaded way

怎甘沉沦 提交于 2020-02-28 19:38:09
问题 I have a method named process in two of my Classes, lets say CLASS-A and CLASS-B . Now in the below loop, I am calling process method of both of my classes sequentially meaning one by one and it works fine but that is the not the way I am looking for. for (ModuleRegistration.ModulesHolderEntry entry : ModuleRegistration.getInstance()) { final Map<String, String> response = entry.getPlugin().process(outputs); // write to database System.out.println(response); } Is there any way, I can call the

How to call same method of a different class in multithreaded way

喜你入骨 提交于 2020-02-28 19:34:06
问题 I have a method named process in two of my Classes, lets say CLASS-A and CLASS-B . Now in the below loop, I am calling process method of both of my classes sequentially meaning one by one and it works fine but that is the not the way I am looking for. for (ModuleRegistration.ModulesHolderEntry entry : ModuleRegistration.getInstance()) { final Map<String, String> response = entry.getPlugin().process(outputs); // write to database System.out.println(response); } Is there any way, I can call the

多线程IO操作(扫描文件夹并计算总大小)

走远了吗. 提交于 2020-02-28 11:55:02
场景为,给到一个硬盘上文件或文件夹,(当然文件夹时,多线程的优势才能越发体现出来),得到该文件或文件夹的大小和计算该结果所需要的时间。 首先是单线程下的例子,这个可难不倒大家,代码如下: public class TotalFileSizeSequential { private long getTotalSizeOfFilesInDir(final File file) { if (file.isFile()) return file.length(); final File[] children = file.listFiles(); long total = 0; if (children != null) for(final File child : children) total += getTotalSizeOfFilesInDir(child); return total; } public static void main(final String[] args) { final long start = System.nanoTime(); final long total = new TotalFileSizeSequential() .getTotalSizeOfFilesInDir(new File("D:/idea_ws")); final long

Runnable locked (park) using ExecutorService and BlockingQueue

痞子三分冷 提交于 2020-01-25 04:18:06
问题 Note: I understand the rules site, but I can't to put all code (complex/large code). I wish I was more specific, but I don't know what part to extract and show. Before you close this question: Obviously, I am willing to refine my question if someone tells me where to look (technical detail). I made a video in order to show my issue. Even to formulate the question, I made a diagram to show the situation. My program has a JTree , showing the relations between Worker . I have a diagram