concurrency

Is an implicit execution context passed down to .par operations?

心已入冬 提交于 2020-02-05 04:58:34
问题 I have this situation: method a: an implicit ec is created method a: calls another method in a Future, i.e Future(anotherMethod) . anotherMethod , and all its subsequent calls no longer have the ec from method a in scope. Example code: class Foo { private implicit val ec: ExecutionContextExecutor = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(Runtime.getRuntime.availableProcessors())) private val anotherClass = new Bar() def methodA() = Future(anotherClass.anotherMethod()) } I'm

Why timed lock technique doesn't work if multiple locks are acquired due to the nesting of method calls

佐手、 提交于 2020-02-05 04:55:26
问题 Quote from java concurrency in practice: Using timed lock acquisition to acquire multiple locks can be effective against deadlock even when timed locking is not used consistently throughout the program. If a lock acquisition times out, you can release the locks, back off and wait for a while, and try again, possibly clearing the deadlock condition and allowing the program to recover. ( This technique works only when the two locks are acquired together; if multiple locks are acquired due to

Applet Flickers even after using using Double Buffering

荒凉一梦 提交于 2020-02-05 04:27:10
问题 I am trying to make a 2 player Pong Applet where the user controls the paddle using mouse. I have used the concept of Double Buffering , but the Applet still flickers !!! What is the mistake I am committing ? import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.util.Timer; import javax.swing.JApplet; public class Pong extends JApplet implements Runnable, MouseMotionListener { Ball ball;

How to do a database lock in AppEngine (GAE)?

流过昼夜 提交于 2020-02-03 05:40:28
问题 In GAE, I've got a table full of "one offs" -- things like "last-used sequence number" and the like that don't really fall into other tables. It's a simple String-key with String-value pair. I've got some code to grab a named integer and increment it, like so: @PersistenceCapable(detachable="true") public class OneOff { @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) private Key key; @Persistent private String dataKey; @Persistent private String value; public OneOff

Concurrent writes to different locations in the same cache line

烈酒焚心 提交于 2020-02-03 05:14:26
问题 Suppose I have a C++11 application where two threads write to different but nearby memory locations, using simple pointers to primitive types. Can I be sure that both these writes will end up in memory eventually (probably after both have reached a boost::barrier), or is there a risk that both CPU cores hold their own cache line containing that data, and the second core flushing its modification to RAM will overwrite and undo the modification done by the first write? I hope that cache

what is meant by the concurrent execution of database transactions in a multiuser system? why concurrency control is needed?

给你一囗甜甜゛ 提交于 2020-02-03 03:26:13
问题 what is meant by the concurrent execution of database transactions in a multiuser system? why concurrency control is needed? I'm having trouble with this. and what are some informal examples for concurrency control. any help would be greatly appreciated. 回答1: Concurrent execution of database transactions in a multi-user system means that any number of users can use the same database at the same time. Concurrency control is needed in order to avoid inconsistencies in the database. Here is an

what is meant by the concurrent execution of database transactions in a multiuser system? why concurrency control is needed?

故事扮演 提交于 2020-02-03 03:26:12
问题 what is meant by the concurrent execution of database transactions in a multiuser system? why concurrency control is needed? I'm having trouble with this. and what are some informal examples for concurrency control. any help would be greatly appreciated. 回答1: Concurrent execution of database transactions in a multi-user system means that any number of users can use the same database at the same time. Concurrency control is needed in order to avoid inconsistencies in the database. Here is an

When does concurrency/multithreading help improve performance?

余生颓废 提交于 2020-02-03 01:53:13
问题 I have been planning to use concurrency in project after learning it indeed has increased through put for many. Now I have not worked much on multi threading or concurrency so decided to learn and have a simple proof of concept before using it in actual project. Below are the two examples I have tried: 1. With use of concurrency public static void main(String[] args) { System.out.println("start main "); ExecutorService es = Executors.newFixedThreadPool(3); long startTime = new Date().getTime(

C++: Concurrency and destructors

前提是你 提交于 2020-02-02 04:49:57
问题 Suppose you have an object which can be accesed by many threads. A critical section is used to protect the sensitive areas. But what about the destructor? Even if I enter a critical section as soon as I enter the destructor, once the destructor has been called, is the object already invalidated? My train of thought: Say I enter the destructor, and I have to wait on the critical section because some other thread is still using it. Once he is done, I can finish destroying the object. Does this

jvm reordering/visibility effect test

别说谁变了你拦得住时间么 提交于 2020-02-02 03:43:03
问题 While writing some java article I'm trying to reproduce re-ordering in case of unsynchronized object costruction in multithreaded environment. The case when a heavy object is constructed w/o synchonization/volatiles/finals and other threads get access to it right after constructor call. Here is the code I try: public class ReorderingTest { static SomeObject<JPanel>[] sharedArray = new SomeObject[100]; public static void main(String[] args) { for (int i = 0; i < 100; i++) { String name =