concurrency

Java parallel work iterator?

左心房为你撑大大i 提交于 2019-12-30 22:16:26
问题 I'm looking for a class where I can override a method to do the work, and return the results like an iterator. Something like this: ParallelWorkIterator<Result> itr = new ParallelWorkIterator<Result>(trials,threads) { public Result work() { //do work here for a single trial... return answer; } }; while (itr.hasNext()) { Result result = itr.next(); //process result... } This is mainly going to be used for things like monte carlo simulations, but I don't want to have to deal with setting up

Are linq operations on concurrent collections thread safe?

核能气质少年 提交于 2019-12-30 17:45:23
问题 For example is the following code thread safe: ConcurrentQueue<Guid> _queue = new ConcurrentQueue<Guid>(); while(true) { for(int y = 0; y < 3; y++) { if(y % 3 == 0) { System.Threading.Tasks.Task.Run(() => _queue.Enqueue(Guid.NewGuid())); } else if (y % 3 == 1) { Guid x; System.Threading.Tasks.Task.Run(() => _queue.TryDequeue(out x)); } else if(y % 3 == 2) { System.Threading.Tasks.Task.Run(() => { if (_queue.Any(t => t == testGuid)) { // Do something } }); } } Edit: Apparently the title wasn't

Data has always changed(SQL Server Management Studio)

Deadly 提交于 2019-12-30 12:54:07
问题 I am using SQL Server Management studio and keep getting the same error, and the only way to get rid of it(usually) is to reset the SQL server(which is very annoying, and sometimes impossible from my remote machine) When I add a row to a table, and then I goto "Edit Top 200 Rows" it all displays and acts fine, and I go to a field I want to change. Then I change something like 0 -> 1 and then I get a nice friendly popup saying "Data has changed since the Results Pane was last retrieved...

Data has always changed(SQL Server Management Studio)

若如初见. 提交于 2019-12-30 12:52:28
问题 I am using SQL Server Management studio and keep getting the same error, and the only way to get rid of it(usually) is to reset the SQL server(which is very annoying, and sometimes impossible from my remote machine) When I add a row to a table, and then I goto "Edit Top 200 Rows" it all displays and acts fine, and I go to a field I want to change. Then I change something like 0 -> 1 and then I get a nice friendly popup saying "Data has changed since the Results Pane was last retrieved...

What is the reason behind “get” method implementation of AtomicMarkableReference in java?

故事扮演 提交于 2019-12-30 11:17:13
问题 In java an AtomicMarkableReference can be used to update atomically an object reference along with a mark bit. The javadoc states: Implementation note: This implementation maintains markable references by creating internal objects representing "boxed" [reference, boolean] pairs. This is true according to what can be seen in the java 8 source code of the class: package java.util.concurrent.atomic; public class AtomicMarkableReference<V> { private static class Pair<T> { final T reference; final

JRuby script with Rubeus and Swing exiting once packaged into jar using warble

独自空忆成欢 提交于 2019-12-30 11:02:00
问题 I am trying to package a simple JRuby script into a jar file. The script uses Rubeus::Swing and runs correctly when executed with the JRuby interpreter. require 'rubygems' require 'rubeus' class Example01 extend Rubeus::Swing def show JFrame.new("Rubeus Swing Example 01") do |frame| frame.visible = true end end end Example01.new.show Once I package the script into a JAR with warble , when I execute: java -jar jtest.jar ... the JFrame window shows up and instantly closes. There is no

Marking servlet instance variables defined in “init” as “volatile”

有些话、适合烂在心里 提交于 2019-12-30 09:51:09
问题 Is it necessary to mark all the servlet instance variables as "volatile" (or to access them from within synchronized sections)? Including those defined in the "init" method, and not modified afterwards? I understand that the "init" method is called by one thread, and the variable will be accessed by another thread, so it seems to be necessary. Or maybe not? Is there any mechanism that guarantees that the current values of instance variables will be visible to all the other threads when the

How to implement Future as Applicative in Scala?

只愿长相守 提交于 2019-12-30 09:05:31
问题 Suppose I need to run two concurrent computations, wait for both of them, and then combine their results. More specifically, I need to run f1: X1 => Y1 and f2: X2 => Y2 concurrently and then call f: (Y1, Y2) => Y to finally get a value of Y . I can create future computations fut1: X1 => Future[Y1] and fut2: X2 => Future[Y2] and then compose them to get fut: (X1, X2) => Future[Y] using monadic composition. The problem is that monadic composition implies sequential wait . In our case it implies

Analyzing Multithreaded Programs [closed]

倖福魔咒の 提交于 2019-12-30 08:35:54
问题 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 6 years ago . We have a codebase that is several years old, and all the original developers are long gone. It uses many, many threads, but with no apparent design or common architectural principles. Every developer had his own style of multithreaded programming, so some threads communicate with one another using queues, some

Immutability of string and concurrency

依然范特西╮ 提交于 2019-12-30 08:34:12
问题 Should we synchronize on writing strings? Since string is immutable we will never get inconsistent state between write and read from the 2 different threads, right? On other words, why we don't have atomic for string type? 回答1: string values are immutable, but variables are not. Variables are–what their name say– variable , their values can be changed. You don't need synchronization for accessing a string value, that can't change. If a string value is handed to you, that (the content of the