multithreading

keep 2 pictures open for a while in memory game in java

天大地大妈咪最大 提交于 2020-02-04 10:57:49
问题 hi there i am working on a project(card matching game) and it is almost finished but the things is when i clicked on second button to open the picture if it not same with first it suddenly closed. well nothings is wrong but user must see the picture for a while(maybe 2 second). so i used Thread.sleep(2000) but i doesnt work properly. it sets icon null and then start to wait 2 seconds. here is my code a tried to make a SSCCE, import java.awt.BorderLayout; import java.awt.Color; import java.awt

keep 2 pictures open for a while in memory game in java

a 夏天 提交于 2020-02-04 10:57:04
问题 hi there i am working on a project(card matching game) and it is almost finished but the things is when i clicked on second button to open the picture if it not same with first it suddenly closed. well nothings is wrong but user must see the picture for a while(maybe 2 second). so i used Thread.sleep(2000) but i doesnt work properly. it sets icon null and then start to wait 2 seconds. here is my code a tried to make a SSCCE, import java.awt.BorderLayout; import java.awt.Color; import java.awt

Is iterating over a list retrieved in a synchronized block thread-safe?

痴心易碎 提交于 2020-02-04 04:56:51
问题 I am a bit confused regarding one pattern I have seen in some legacy code of ours. The controller uses a map as a cache, with an approach that should be thread safe, however I am still not confident it indeed is. We have a map, which is properly synchronized during addition and retrieval, however, there is a bit of logic outside of the synchronized block, that does some additional filtering. ( the map itself and the lists are never accessed outside of this method , so concurrent modification

multi-thread opening file hangs when fanotify is on

空扰寡人 提交于 2020-02-04 03:48:17
问题 I use this fanotify sample to monitor open/access perms on the whole file system(/): http://git.infradead.org/users/eparis/fanotify-example.git. Then I have a test program with multiple threads, each thread iterate the sample foder and open/close the files in it, sometimes my program hangs at open(). OS: Ubuntu 2.6.38-11 x86_64. Is it a bug of fanotify that it does not support multiple-thread opening? The code of my test program: #include <stdlib.h> #include <stdio.h> #include <pthread.h>

Java 7 G1GC strange behaviour

旧时模样 提交于 2020-02-04 01:25:15
问题 Recently I have tried to use G1GC from jdk1.7.0-17 in my java processor which is processing a lot of similar messages received from an MQ (about 15-20 req/sec). Every message is processed in the separate thread (about 100 threads in stable state) that serviced by Java limited thread pool. Surprisingly, I detected the strange behaviour - as soon as GC starts the full gc cycle it begins to use significant processing time (up to 100% CPU and even more). I was doing refactoring of the code

Java 7 G1GC strange behaviour

荒凉一梦 提交于 2020-02-04 01:25:12
问题 Recently I have tried to use G1GC from jdk1.7.0-17 in my java processor which is processing a lot of similar messages received from an MQ (about 15-20 req/sec). Every message is processed in the separate thread (about 100 threads in stable state) that serviced by Java limited thread pool. Surprisingly, I detected the strange behaviour - as soon as GC starts the full gc cycle it begins to use significant processing time (up to 100% CPU and even more). I was doing refactoring of the code

Windows Forms Form hanging after calling show from another thread

耗尽温柔 提交于 2020-02-03 10:48:18
问题 I have application which has some networking code which runs asynchronously. I have attached some events to be thrown when no connection to server and I'm creating some "operation failed" form when this happens. The problem is that my form hangs after creation. I read about that and I tried to do with: public void ShowView() { if (this.InvokeRequired) { Action a = new Action(ShowView); this.Invoke(a); } else this.Show(); } And problem was still present. Than I found that if control was not

Windows Forms Form hanging after calling show from another thread

半城伤御伤魂 提交于 2020-02-03 10:46:10
问题 I have application which has some networking code which runs asynchronously. I have attached some events to be thrown when no connection to server and I'm creating some "operation failed" form when this happens. The problem is that my form hangs after creation. I read about that and I tried to do with: public void ShowView() { if (this.InvokeRequired) { Action a = new Action(ShowView); this.Invoke(a); } else this.Show(); } And problem was still present. Than I found that if control was not

How to use dispatch_async_f?

大城市里の小女人 提交于 2020-02-03 05:02:28
问题 The function that I want queued takes no parameters. What do I pass in as paramContext ? Passing in NULL generates the compile error "Invalid use of void expression". I do not want to add a parameter to my function just to make it compile - how do I make this work? Mac OS X Snowleopard, Xcode 3.2.6 with Objective-C 回答1: You need to wrap the function somehow. The easiest way is actually to use dispatch_async() instead, as in dispatch_async(queue, ^{ myFunc() }); 回答2: While you can just pass 0

How does thread pooling works, and how to implement it in an async/await env like NodeJS?

浪尽此生 提交于 2020-02-03 04:36:30
问题 I need to run a function int f(int i) with 10_000 parameters and it takes around 1sec to execute due to I/O time. In a language like Python, I can use threads (or async/await , I know, but I'll talk about it later) to parallelize this task. If I want to always have 10 running threads, and to split the task between them, I can use ThreadingPool : def f(p): x = [...] return x p = ThreadPool() xs = p.map(f, range(10_000)) But how does it work ? If I want to implement a similar thing with, let's