concurrency

Persistent Variables in ExecutorService (Java)

余生长醉 提交于 2020-01-11 09:01:52
问题 I've created a pool of 4 worker threads to process some files. In the test there's about 200 of them. The thread pool version is already about 3 times faster than doing it sequentially but there is room for improvement. The biggest bottleneck (ignoring disk I/O) is that I need to instantiate a new MessageDigest object. In the single threaded version I just had 1. In this version I have 200. What I was wondering was, is it possible to have a variable local to the thread in the work pool? That

Persistent Variables in ExecutorService (Java)

爷,独闯天下 提交于 2020-01-11 09:01:48
问题 I've created a pool of 4 worker threads to process some files. In the test there's about 200 of them. The thread pool version is already about 3 times faster than doing it sequentially but there is room for improvement. The biggest bottleneck (ignoring disk I/O) is that I need to instantiate a new MessageDigest object. In the single threaded version I just had 1. In this version I have 200. What I was wondering was, is it possible to have a variable local to the thread in the work pool? That

Thread safety of the plus operator for Strings, optimizations included

我们两清 提交于 2020-01-11 08:51:50
问题 This post says that a += b is the equivalent of a = new StringBuilder() .append(a) .append(b) .toString(); Let's say I have this code: public class MultiThreadingClass extends SomeThirdPartyClassThatExtendsObject{ public void beginmt(String st) throws IOException { //st is a thread number st = new File("c:\\somepath").getCanonicalPath()+"\\"+st; System.out.println(st); } } Assume that beginmt runs multiple times simultaneously (with thread numbers 1 to 15500) on a single instance of

how to use Multithreading With ArrayList in Java

空扰寡人 提交于 2020-01-11 08:03:11
问题 Hello , I have a program that works perfectly , unfortunantly i have some calculs that takes a lot of time , some minutes .. My objectif is to use multithreading to accelerate the parts that take so much time ,. In this Example I give the prototype of the part that i should parallelize public static ArrayList<Object2> createListOfObject2(ArrayList<Object1> mylist) { ArrayList<Object2> listToReturn = new ArrayList<>(); Object2 object2; for (int i = 0; i < mylist.size(); i++) { for (int j = 0;

apply_async callback function not being called

佐手、 提交于 2020-01-11 07:19:28
问题 I am a newbie to python,i am have function that calculate feature for my data and then return a list that should be processed and written in file.,..i am using Pool to do the calculation and then and use the callback function to write into file,however the callback function is not being call,i ve put some print statement in it but it is definetly not being called. my code looks like this: def write_arrow_format(results): print("writer called") results[1].to_csv("../data/model_data/feature-"

Why does ManualResetEvent fail to work in this synchronous call using Silverlight 4?

耗尽温柔 提交于 2020-01-11 05:22:05
问题 Let's put aside for the moment, the question of whether synchronous-like operations should even be attempted within the context of a Silverlight app. If I use ManualResetEvent as in the following code: static string result; static AutoResetEvent are = new AutoResetEvent(false); static ManualResetEvent mre = new ManualResetEvent(false); public static string AsyncCall() { string url = "https://stackoverflow.com/feeds/tag/silverlight"; WebClient w = new WebClient(); w.DownloadStringCompleted +=

how to instantiate Unit in Scala?

流过昼夜 提交于 2020-01-11 05:13:50
问题 All I desire is to use some concurrent Set (that appears not to exist at all). Java uses java.util.concurrent.ConcurrentHashMap<K, Void> to achieve that behavior. I'd like to do sth similar in Scala so I created instance of Scala HashMap (or Java ConcurrentHashMap) and tried to add some tuples: val myMap = new HashMap[String, Unit]() myMap + (("myStringKey", Unit)) This of course crashed the process of compilation as Unit is abstract and final. How to make this work? Should I use Any / AnyRef

How to detect if a program has been compiled using -threaded?

寵の児 提交于 2020-01-11 04:32:05
问题 I'm working on a Haskell daemon that uses POSIX fork/exec together with file locking mechanism. My experiments show that file locks aren't inherited during executeFile with -threaded runtime (see also this thread), no matter if I use +RTS -N or not. So I'd like to add a check to be sure that the daemon ins't compiled with -threaded . Is there a portable way to detect it? 回答1: There is a value in Control.Concurrent for this, for example: module Main (main) where import Control.Concurrent main

How to ensure that std::thread are created in multi core?

拥有回忆 提交于 2020-01-11 02:32:47
问题 I am using visual studio 2012. I have a module, where, I have to read a huge set of files from the hard disk after traversing their corresponding paths through an xml. For this i am doing std::vector<std::thread> m_ThreadList; In a while loop I am pushing back a new thread into this vector, something like m_ThreadList.push_back(std::thread(&MyClass::Readfile, &MyClassObject, filepath,std::ref(polygon))); My C++11 multi threading knowledge is limited.The question that I have here , is , how do

import inside of a Python thread

十年热恋 提交于 2020-01-10 22:27:47
问题 I have some functions that interactively load python modules using __import__ I recently stumbled upon some article about an "import lock" in Python, that is, a lock specifically for imports (not just the GIL). But the article was old so maybe that's not true anymore. This makes me wonder about the practice of importing in a thread. Are import / __import__ thread safe? Can they create dead locks? Can they cause performance issues in a threaded application? EDIT 12 Sept 2012 Thanks for the