concurrency

How is it possible for a program to contain exclusively thread-safe classes, but not be thread-safe?

天大地大妈咪最大 提交于 2020-01-30 06:03:46
问题 I am reading "java concurrency in practice", and the author says: "A program that consists entirely of thread-safe classes may not be thread-safe". How is this possible? I don't seem to understand, can someone provide an example? 回答1: An example would be individual methods on a class that are thread safe, but they are not atomic if you invoke more than one. E.g. if (!threadSafeCollection.contains(thing)) { threadSafeCollection.add(thing); } This may yield incorrect results if another thread

Java - Exception in thread “main” java.util.ConcurrentModificationException

送分小仙女□ 提交于 2020-01-30 03:25:29
问题 Is there any way I can modify the HashMap values of a particular key while iterating over it? A sample program is given below: public static void main(String[] args) { HashMap<Integer,ArrayList<String>> hm = new HashMap<Integer, ArrayList<String>>(); ArrayList<String> ar = new ArrayList<String>(); for(int i=0;i<50;i++){ ar.add(Integer.toString(i)); } hm.put(1, ar); for(String s:hm.get(1)){ hm.get(1).add("hello"); } } Error Thrown: Exception in thread "main" java.util

Java - Exception in thread “main” java.util.ConcurrentModificationException

≯℡__Kan透↙ 提交于 2020-01-30 03:25:09
问题 Is there any way I can modify the HashMap values of a particular key while iterating over it? A sample program is given below: public static void main(String[] args) { HashMap<Integer,ArrayList<String>> hm = new HashMap<Integer, ArrayList<String>>(); ArrayList<String> ar = new ArrayList<String>(); for(int i=0;i<50;i++){ ar.add(Integer.toString(i)); } hm.put(1, ar); for(String s:hm.get(1)){ hm.get(1).add("hello"); } } Error Thrown: Exception in thread "main" java.util

How to ask CompletableFuture use non-daemon threads?

馋奶兔 提交于 2020-01-29 08:43:06
问题 I have wrote following code: System.out.println("Main thread:" + Thread.currentThread().getId()); CompletableFuture<Void> future = CompletableFuture.runAsync(() -> { try { System.out.println("Before sleep thread:" + Thread.currentThread().getId(), + " isDaemon:" + Thread.currentThread().isDaemon()); Thread.sleep(100); System.out.println("After sleep"); } catch (InterruptedException e) { e.printStackTrace(); } }); future.whenComplete((r, e) -> System.out.println("whenCompleted thread:" +

Any good implementation of Actors for C#? [closed]

守給你的承諾、 提交于 2020-01-28 13:22:16
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Is there any good implementation of actors concurrency model for .net/c#? I have to optimize a c# routine and i think that actors model fits perfectly as a solution for my problem. Unfortunately i have experience only with scala implementation. 回答1: You should have a look at MS Concurrency & Coordination Runtime

Any good implementation of Actors for C#? [closed]

徘徊边缘 提交于 2020-01-28 13:22:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Is there any good implementation of actors concurrency model for .net/c#? I have to optimize a c# routine and i think that actors model fits perfectly as a solution for my problem. Unfortunately i have experience only with scala implementation. 回答1: You should have a look at MS Concurrency & Coordination Runtime

Entity Framework IsRowVersion() without concurrency check

不羁岁月 提交于 2020-01-25 21:03:35
问题 We have a table that has a column called Version that is mapped as a SQL rowversion . This is done because we have an external system that maps to our data that relies on this column changing every time the table is updated. Originally we wanted this to be handled by SQL, but now we are finding we have Optimistic Concurrency exceptions. While these exceptions are there to safeguard data getting overwritten, for our case we do not care about this. We simply want the timestamp to continue

How to handle errors and terminate Goroutine using WaitGroup

隐身守侯 提交于 2020-01-25 08:49:06
问题 I have been playing around with Goroutines, Channels and WaitGroup today and I am finally starting to understand the concept, after just been reading about it for a while. My problem is that I am unsure how I handle errors when working like this, mainly because of the WaitGroup I use. When using the WaitGroup, I start by adding the amount of goroutines that will be executed, but what if an error happens during one of these? package main import ( "errors" "sync" ) var waitGroup sync.WaitGroup

Linux Socket Input Notification on a Client-Server application

ε祈祈猫儿з 提交于 2020-01-25 07:33:09
问题 This question is a followup to this question and answer I'm building a minimalistic remote access programm on Linux using SSL and socket programming. The problem arose in the following protocol chain Client sends command Server recieves it Server spawns a child, with input, output and error dup -ed with the server-client socket (so the input and output would flow directly though the sockets) Server waits for the child and waits for a new command When using SSL, you cannot use read and write

Prevent user from manipulating query string parameter

牧云@^-^@ 提交于 2020-01-25 04:26:08
问题 Situation: Unregistered user visits website and issues a request for an item. As per the current data flow, this request gets inserted in db first and the request id is carried over in the url of the subsequent pages henceforth( where user gets to add in further info). Problem: User can change the id. What i have done so far: As soon as i retrieve the id after request is inserted by using lastInsertId(), i store it inside a session variable and check in the subsequent pages against the id