concurrency

java access an object in different threads

試著忘記壹切 提交于 2019-12-29 07:48:07
问题 I have searched a lot but not able to find particular solution. There are also some question regarding this on stackoverflow but i am not able to find satisfactory answer so i am asking it again. I have a class as follow in java . I know how to use threads in java. //please do not consider syntax if there is printing mistake, as i am typing code just for showing the concept in my mind public class myclass{ private List<String> mylist=new ArrayList<String>(); public addString(String str){ /

GLSL SpinLock only Mostly Works

☆樱花仙子☆ 提交于 2019-12-29 07:18:22
问题 I have implemented a depth peeling algorithm using a GLSL spinlock (inspired by this). In the following visualization, notice how overall the depth peeling algorithm functions correctly (first layer top left, second layer top right, third layer bottom left, fourth layer bottom right). The four depth layers are stored into a single RGBA texture. Unfortunately, the spinlock sometimes fails to prevent errors--you can see little white speckles, particularly in the fourth layer. There's also one

A tested implementation of Peterson Lock algorithm?

痴心易碎 提交于 2019-12-29 07:00:06
问题 Does anyone know of a good/correct implementation of Peterson's Lock algorithm in C? I can't seem to find this. Thanks. 回答1: I won't make any assertions about how good or correct the implementation is, but it was tested (briefly). This is a straight translation of the algorithm described on wikipedia. struct petersonslock_t { volatile unsigned flag[2]; volatile unsigned turn; }; typedef struct petersonslock_t petersonslock_t; petersonslock_t petersonslock () { petersonslock_t l = { { 0U, 0U }

Is there a way to force parallelStream() to go parallel?

北战南征 提交于 2019-12-29 06:59:47
问题 If the input size is too small the library automatically serializes the execution of the maps in the stream, but this automation doesn't and can't take in account how heavy is the map operation. Is there a way to force parallelStream() to actually parallelize CPU heavy maps? 回答1: There seems to be a fundamental misunderstanding. The linked Q&A discusses that the stream apparently doesn’t work in parallel, due to the OP not seeing the expected speedup. The conclusion is that there is no

Is there a way to force parallelStream() to go parallel?

℡╲_俬逩灬. 提交于 2019-12-29 06:59:14
问题 If the input size is too small the library automatically serializes the execution of the maps in the stream, but this automation doesn't and can't take in account how heavy is the map operation. Is there a way to force parallelStream() to actually parallelize CPU heavy maps? 回答1: There seems to be a fundamental misunderstanding. The linked Q&A discusses that the stream apparently doesn’t work in parallel, due to the OP not seeing the expected speedup. The conclusion is that there is no

How to wait for a transition to end in javafx 2.1?

狂风中的少年 提交于 2019-12-29 05:31:06
问题 My scene consists only of an ImageView, displaying an image. I would like to fade the image to black (assigned color of the scene), then after some time, fade from black to the image again. I found the FadeTransition very fitting for this purpose. This is a piece of my code: // fade to black transition FadeTransition ft1 = new FadeTransition(Duration.millis(2000), myImageView); ft1.setFromValue(1.0); ft1.setToValue(0.0); ft1.play(); // fade from black transition FadeTransition ft2 = new

Pre-initializing a pool of worker threads to reuse connection objects (sockets)

白昼怎懂夜的黑 提交于 2019-12-29 03:29:13
问题 I need to build a pool of workers in Java where each worker has its own connected socket; when the worker thread runs, it uses the socket but keeps it open to reuse later. We decided on this approach because the overhead associated with creating, connecting, and destroying sockets on an ad-hoc basis required too much overhead, so we need a method by which a pool of workers are pre-initializaed with their socket connection, ready to take on work while keeping the socket resources safe from

Need simple explanation how “lock striping” works with ConcurrentHashMap

一曲冷凌霜 提交于 2019-12-29 03:19:05
问题 According to Java Concurrency in Practice, chapter 11.4.3 says: Lock splitting can sometimes be extended to partition locking on a variablesized set of independent objects, in which case it is called lock striping. For example, the implementation of ConcurrentHashMap uses an array of 16 locks, each of which guards 1/16 of the hash buckets; bucket N is guarded by lock N mod 16. I still have problems to understand and visualize the lock striping and buckets mechanism. Can someone explain this

Why doesn't this thread pool get garbage collected?

只愿长相守 提交于 2019-12-29 03:18:25
问题 In this code example, the ExecutorService is used one and allowed to go out of scope. public static void main(String[] args) { ExecutorService executorService = Executors.newFixedThreadPool(3); executorService.submit(new Runnable() { public void run() { System.out.println("hello"); } }); } Once executorService is out of scope, it should get collected and finalized. The finalize() method in ThreadPoolExecutor calls shutdown(). /** * Invokes {@code shutdown} when this executor is no longer *

How are you taking advantage of Multicore?

旧街凉风 提交于 2019-12-29 02:18:11
问题 As someone in the world of HPC who came from the world of enterprise web development, I'm always curious to see how developers back in the "real world" are taking advantage of parallel computing. This is much more relevant now that all chips are going multicore, and it'll be even more relevant when there are thousands of cores on a chip instead of just a few. My questions are: How does this affect your software roadmap? I'm particularly interested in real stories about how multicore is