java-threads

Using a ScheduledExecutorService to run a task on a periodic basis in Java

送分小仙女□ 提交于 2021-02-11 15:00:49
问题 I am working on a program that will read data from a data source, and publish that data as it is read. I have a reader and a writer, the reader spawns several threads to read all the data it needs to read, puts the data into a queue, and the writer reads the data from the queue an publishes it. I have a controller for my readers and a controller for my writers. The controllers implement the Callable interface, but could implement the Runnable interface as my call return is Void . I want to

Using a ScheduledExecutorService to run a task on a periodic basis in Java

我的未来我决定 提交于 2021-02-11 14:59:42
问题 I am working on a program that will read data from a data source, and publish that data as it is read. I have a reader and a writer, the reader spawns several threads to read all the data it needs to read, puts the data into a queue, and the writer reads the data from the queue an publishes it. I have a controller for my readers and a controller for my writers. The controllers implement the Callable interface, but could implement the Runnable interface as my call return is Void . I want to

Parallelized Matrix Multiplication

安稳与你 提交于 2021-02-08 06:19:15
问题 I am trying to parallelize the multiplication of two matrix A , B . Unfortunately the serial implementation is still faster than the parallel one or the speedup is too low. (with matrix dimension = 512 the speedup is like 1.3 ). Probably something is fundamentally wrong. Can someone out there give me a tip? double[][] matParallel2(final double[][] matrixA, final double[][] matrixB, final boolean parallel) { int rows = matrixA.length; int columnsA = matrixA[0].length; int columnsB = matrixB[0]

How to pause/delay, a specific part of my code

穿精又带淫゛_ 提交于 2021-02-05 11:47:28
问题 I have a paintComponent method, inside a class.It makes a grid of 10*10. And I want to lower the frame rate, so that every time the function colors a rectangle in the grid, I can see the progression public void paint(Graphics g1) { super.paint(g1); Graphics2D g= (Graphics2D) g1; for(Object a: Maze_Generator.list) { Cell c =(Cell)a; if(c.top()) g.drawLine(c.x(), c.y(), c.x()+c.length(), c.y()); if(c.bottom()) g.drawLine(c.x(), c.y()+c.length(),c.x()+c.length(),c.y()+c.length()); if(c.left()) g

How to pause/delay, a specific part of my code

孤人 提交于 2021-02-05 11:47:05
问题 I have a paintComponent method, inside a class.It makes a grid of 10*10. And I want to lower the frame rate, so that every time the function colors a rectangle in the grid, I can see the progression public void paint(Graphics g1) { super.paint(g1); Graphics2D g= (Graphics2D) g1; for(Object a: Maze_Generator.list) { Cell c =(Cell)a; if(c.top()) g.drawLine(c.x(), c.y(), c.x()+c.length(), c.y()); if(c.bottom()) g.drawLine(c.x(), c.y()+c.length(),c.x()+c.length(),c.y()+c.length()); if(c.left()) g

After executing wait(), how long does a thread wait if it does not get notified from other threads?

一世执手 提交于 2021-02-05 04:59:20
问题 In the below example, as the main-thread is not getting notified from the child thread, it should wait forever. But the main-thread is getting executed and the output of the below example is: c l total: 19900 Why is the main-thread getting executed? public class ThreadX extends Thread { static int total = 0; public void run() { synchronized (this) { for (int i = 0; i < 200; i++) { total = total + i; } System.out.println("c"); } } public static void main(String[] args) throws

Java synchronize block on same object in different methods

 ̄綄美尐妖づ 提交于 2021-02-04 16:22:25
问题 I am trying to understand the concept of synchronized blocks in java. As of the documents that I have read, I understood that if we acquire a lock ( synchronized block using an instance variable ) then we cannot acquire a synchronized lock on same object in that class. But when I tried practically using the following snippet I found that my understanding is going wrong. I.e I am able to acquire lock (synchronized block on same instance variable) in two different methods at the same time. When

JVM unable to create a thread in Cloud Foundry

跟風遠走 提交于 2021-01-29 05:02:08
问题 I'm using Spring boot for the application. There is a particular controller when called, makes a couple of independent requests using OkHttpClient. I am using a thread pool of 200 threads to make these calls. It works absolutely fine in the local environment. However, when deployed to cloud foundry, it shows up an error as follows. I have reduced the number of threads to 100 but the problem still remains. These are the memory settings in my CF instance - Instance Memory Limit 8192 MB Memory