concurrency

Refactoring synchronization blocks keeping ordering of execution intact

落爺英雄遲暮 提交于 2021-01-29 10:29:32
问题 I have this synchronized block in one of my classes, whose main responsibility is to capture metrics around service calls. All variables prefixed with _ are class variables and are primitive longs. I am looking to refactor this synchronized block so as to increase the throughput, but keeping the overall accuracy intact. I have a test setup which calls this method from Runnable threads using an executor service. I am doing a comparison on the metrics before and after refactoring. public

Netty, concurrent writeAndFlush

人走茶凉 提交于 2021-01-29 08:52:50
问题 Lets say we have some kind of pub/sub protocol. When someone is connecting and subscribing, we can save channel in Map, List or ChannelGroup: @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { super.channelActive(ctx); log.debug("Client connected: {}", ctx.channel().remoteAddress()); clients.add(ctx); } After that, when some message has come or some event has happened, I can notify clients: @Override public void channelRead(ChannelHandlerContext ctx, Object msg)

How to stop Callable tasks in Executor service if exception occur

天大地大妈咪最大 提交于 2021-01-29 08:51:10
问题 I'm trying to implement a sample application to test Callable and ExecutorService interfaces. In my app I have: @Bean("fixedThreadPool") public ExecutorService fixedThreadPool() { return Executors.newFixedThreadPool(5); } Then: public void removeUserIds(Set<String> userIds) { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString("http://localhost:8080/remove"); final List<Callable<String>> callables = new ArrayList<>(); userIds.forEach(userId -> { final Callable<String> task = ()

what happen between after notify_all() and before wait() get the lock?

≯℡__Kan透↙ 提交于 2021-01-29 08:34:49
问题 I test the std::condition_variable using the below code: class CondWait{ public: std::condition_variable cv; std::mutex mu; int i=0; public: void mainTask(){ std::unique_lock<std::mutex> lk(mu); cv.wait(lk); i++; std::cout<<"main task, "<<i<<std::endl; } void notifyTask(){ std::unique_lock<std::mutex> lk(mu); i = 0; std::cout<<"notify task, "<<i<<std::endl; cv.notify_one(); std::cout<<"notify task, sleep 5 sec"<<std::endl; std::this_thread::sleep_for(std::chrono::seconds(5)); } }; int main()

How to stop a sound (while its playing) from another method

醉酒当歌 提交于 2021-01-29 06:29:10
问题 I have some music playing in my program. I want it to switch music depending on certain actions etc. The problem is I have my music begin playing from one method and I am trying to stop it from another method or action event. The other method isnt able to find my clip object because it is not public. Is it possible to make this clip object public for my whole class? I tried making another class just for music. Could someone guide me? Thanks, public void playsound(String filepath){ try {

How to stop a sound (while its playing) from another method

筅森魡賤 提交于 2021-01-29 06:20:49
问题 I have some music playing in my program. I want it to switch music depending on certain actions etc. The problem is I have my music begin playing from one method and I am trying to stop it from another method or action event. The other method isnt able to find my clip object because it is not public. Is it possible to make this clip object public for my whole class? I tried making another class just for music. Could someone guide me? Thanks, public void playsound(String filepath){ try {

C# Semaphores not working as expected, cannot figure out why

三世轮回 提交于 2021-01-29 05:43:56
问题 I am building an ASP.NET (.NET Framework) application in C# I am making API calls to a backend service called "LinuxDocker" and I am trying to limit the number of 12 concurrent calls to it from the ASP.NET application. Here is the code I wrote: private static Semaphore LinuxDockerSemaphore = new Semaphore(12, 12); public static SemaphoreWaiter WaitForLinuxDocker(int timeoutMS = -1) { return new SemaphoreWaiter(LinuxDockerSemaphore, timeoutMS); } public class SemaphoreWaiter : IDisposable {

How to run multiple servlets execution in parallel for Tomcat?

风格不统一 提交于 2021-01-29 04:14:21
问题 I have a Tomcat application, I need two different servlets or the same one to respond in parallel to my requests. The case is I have a first request asking to download medical imaging and I have another AJAX client request fetching images before the first request is completely done. But for some reason, the server does not respond to my second request until the first one is over. What has to be changed in order to achieve concurrent servlets execution? We have a pretty good server with

How to run multiple servlets execution in parallel for Tomcat?

老子叫甜甜 提交于 2021-01-29 04:07:20
问题 I have a Tomcat application, I need two different servlets or the same one to respond in parallel to my requests. The case is I have a first request asking to download medical imaging and I have another AJAX client request fetching images before the first request is completely done. But for some reason, the server does not respond to my second request until the first one is over. What has to be changed in order to achieve concurrent servlets execution? We have a pretty good server with

Assigning to running QFuture

时光毁灭记忆、已成空白 提交于 2021-01-29 02:30:20
问题 Can I assign another QFuture object to already running QFuture object? Like in the example below: QFuture<int> future = QtConcurrent::run(function); future = QtConcurrent::run(anotherFunciton); //assume that future is still running at this point I realize that this particular example doesn't make much sense, it's just for the sake of example. Is it safe to make such an assigment, assuming that the result of the first function doesn't interest me anymore? Or do I have to cancel it first? And