concurrency

what is transactional memory in comparison to actor model and locks

可紊 提交于 2019-12-25 08:05:25
问题 What is the transactional memory in comparison to actor-based and lock-based synchronization? As far as I understand it is another mechanism of concurrency control. Or it is something completely different to actors, events, locks etc.? 回答1: Transactional Memory (TM) is a lock free synchronization methodology. In a lock based synchronization mechanism, one thread acquires the lock and enters the synchronized block whilst others wait until the lock becomes available. In TM, threads don't wait

How to manage pool thread termination in ThreadPoolExecutor?

北战南征 提交于 2019-12-25 07:50:40
问题 Quote from concurrency in practice: To set an UncaughtExceptionHandler for pool threads, provide a ThreadFactory to the ThreadPoolExecutor constructor. (As with all thread manipulation, only the thread's owner should change its UncaughtExceptionHandler.) The standard thread pools allow an uncaught task exception to terminate the pool thread, but use a try-finally block to be notified when this happens so the thread can be replaced. Without an uncaught exception handler or other failure

Is it possible to use concurrent.futures to execute a function/method inside a tkinter class following an event? If yes, how?

老子叫甜甜 提交于 2019-12-25 07:47:45
问题 I am trying to use the pool of workers provided by concurrent.futures.ProcessPoolExecutor to speed up the performance of a method inside a tkinter class. This is because executing the method is cpu intensive and "parallelizing" it should shorten the time to complete it. I hope to benchmark it's performance against a control - a serial execution of the same method. I have written a tkinter GUI test code to perform this benchmark. The serial execution of the method works but the concurrent part

Execute only one instance of SwingWorker

ε祈祈猫儿з 提交于 2019-12-25 07:43:27
问题 Suppose I have a Java GUI which shows in a panel 40 Batch objects from a selected zone which can go from A to Z. The 40 Batch objects are queried from database which caches them by zone so that each request for a zone doesn't involve the database every time. public class BatchView { private int drawIt(Graphics g, String zone) { for(int i = 0; i<40; i++) { Batch tmpBatch = BatchDAO.getBatch(zone, i); //draw the tmpBatch object } } } public class BatchDAO { public static MyCache cache = new

Printing the stack trace from a newly created thread when an unchecked exception is thrown in Eclipse

可紊 提交于 2019-12-25 07:32:57
问题 Why am I unable to see the stack trace in Eclipse's console when an unchecked Exception is thrown from a thread different from the main thread? For example: ScheduledThreadPoolExecutor scheduledExecutor; scheduledExecutor.scheduleAtFixedRate(new Log(), 0, LOGGING_FREQUENCY_MS, TimeUnit.MILLISECONDS); public class Log implements Runnable { public void run() { //NullPointerException is thrown } } I get no output. But if I do: ScheduledThreadPoolExecutor scheduledExecutor; scheduledExecutor

How can I start a server in a background thread and know that the server did not throw exception on startup?

心不动则不痛 提交于 2019-12-25 07:21:51
问题 I have a class which encapsulates a Server Socket i.e. a server functionality. The interface of the class is: class Server{ public void start(); public void stop(); } the start is as follows: public void start(){ ExecutorService tp = Executors.newSingleThreadExecutor(); while(!stop){ try { Socket clientConnection = serverSocket.accept(); tp.execute(new ClientProcessor(clientConnection)); } catch (IOException e) { stop = true; } } I have trouble figuring out how I would start this without

DbUpdateConcurrencyException when editing data that already exists even though I pass the variables needed

落花浮王杯 提交于 2019-12-25 07:00:31
问题 I'm getting the DbUpdateConcurrencyException error even though I am passing the OrderID to the OrderItem form. It works on Create and Delete , but it keeps kicking me out for Edit . Can anyone please suggest a fix or let me know if I'm doing something wrong? I get this Concurrency Exception Error : System.Data.Entity.Infrastructure.DbUpdateConcurrencyException was unhandled by user code HResult=-2146233087 Message=Store update, insert, or delete statement affected an unexpected number of rows

Alamofire never calls encodingCompletion for upload with MultipartFormData when main thread is waiting for it to run

风流意气都作罢 提交于 2019-12-25 06:57:35
问题 I have code of this form: func myFunction(<...>, completionHandler: (ResponseType) -> Void) { <prepare parameters> mySessionManager.upload(multipartFormData: someClosure, to: saveUrl, method: .post, headers: headers) { encodingResult in // encodingCompletion switch encodingResult { case .failure(let err): completionHandler(.error(err)) case .success(let request, _, _): request.response(queue: self.asyncQueue) { response in // upload completion <extract result> completionHandler(.success

CoreNLP on Apache Spark

谁都会走 提交于 2019-12-25 06:14:45
问题 I'm not sure if this is related to Spark or NLP. Please help.I'm currently trying to run Stanford CoreNLP Library on Apache Spark and when I try to run it on multiple cores, I get the following exception. I'm using the latest NLP Library which is thread safe. This is happening during the map phase on line. pipeline.annotate(document); java.util.ConcurrentModificationException at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901) at java.util.ArrayList$Itr.next(ArrayList.java

only continue loop if method has finished

被刻印的时光 ゝ 提交于 2019-12-25 06:04:11
问题 I have a for/in loop like so: for(NSString *paymentId in success){ [self getPaymentDetails:paymentId]; } The method getPaymentDetails is asynchronous. How do I create a completion block to only continue the for/in loop if the method has finished? details the method getPaymentDetails looks like this: -(void)getPaymentDetails:(NSString *)paymentId{ PFUser *currentUser = [PFUser currentUser]; [PFCloud callFunctionInBackground:@"getpaymentdetails" withParameters:@{@"objectid": paymentId, @"userid