concurrency

CREATE SCHEMA IF NOT EXISTS raises duplicate key error

此生再无相见时 提交于 2020-01-14 07:33:21
问题 To give some context, the command is issued inside a task, and many task might issue the same command from multiple workers at the same time. Each tasks tries to create a postgres schema. I often get the following error: IntegrityError: (IntegrityError) duplicate key value violates unique constraint "pg_namespace_nspname_index" DETAIL: Key (nspname)=(9621584361) already exists. 'CREATE SCHEMA IF NOT EXISTS "9621584361"' Postgres version is PostgreSQL 9.4rc1. Is it a bug in Postgres? 回答1: This

CREATE SCHEMA IF NOT EXISTS raises duplicate key error

ε祈祈猫儿з 提交于 2020-01-14 07:33:09
问题 To give some context, the command is issued inside a task, and many task might issue the same command from multiple workers at the same time. Each tasks tries to create a postgres schema. I often get the following error: IntegrityError: (IntegrityError) duplicate key value violates unique constraint "pg_namespace_nspname_index" DETAIL: Key (nspname)=(9621584361) already exists. 'CREATE SCHEMA IF NOT EXISTS "9621584361"' Postgres version is PostgreSQL 9.4rc1. Is it a bug in Postgres? 回答1: This

Limiting concurrent access to a method

风流意气都作罢 提交于 2020-01-14 04:45:13
问题 I have a problem with limiting concurrent access to a method. I have a method MyService that can be called from many places at many times. This method must return a String , that should be updated according to some rules. For this, I have an updatedString class. Before getting the String , it makes sure that the String is updated, if not, it updates it. Many threads could read the String at the same time but ONLY ONE should renew the String at the same time if it is out of date. public final

Concurrent use of JaxWsPortProxyFactoryBean

跟風遠走 提交于 2020-01-14 04:27:10
问题 I'm using JaxWsPortProxyFactoryBean (Spring 3.1.2) to access a remote web service. In the documentation I can't find anything on concurrent usage of the JaxWsPortProxyFactoryBean . Is it allowed to use it concurrently with from threads? And if so, is it possible to dynamically change the enpoint address so that different threads can use a different endpoint for the same JaxWsPortProxyFactoryBean ? 回答1: About concurrently using you can see: JaxWsPortProxyFactoryBean.setExecutor(java.util

Can't stop a task which is started using ExecutorService

家住魔仙堡 提交于 2020-01-13 18:06:04
问题 Sorry I have to open a new thread to describe this problem. This morning I asked this question, there're some replies but my problem is still not solved. This time I will attach some runnable code(simplified but with the same problem) for you to reproduce the problem: public class ThreadPoolTest { public static void main(String[] args) throws Exception { final ExecutorService taskExecutor = Executors.newFixedThreadPool(5); Future<Void> futures[] = new Future[5]; for (int i = 0; i < futures

Why does this simple threaded program get stuck?

本秂侑毒 提交于 2020-01-13 13:31:59
问题 Take a look at this simple Java program: import java.lang.*; class A { static boolean done; public static void main(String args[]) { done = false; new Thread() { public void run() { try { Thread.sleep(1000); // dummy work load } catch (Exception e) { done = true; } done = true; } }.start(); while (!done); System.out.println("bye"); } } On one machine, it prints "bye" and exits right away, while on another machine, it doesn't print anything and sits there forever. Why? 回答1: This is because

Why does this simple threaded program get stuck?

情到浓时终转凉″ 提交于 2020-01-13 13:31:08
问题 Take a look at this simple Java program: import java.lang.*; class A { static boolean done; public static void main(String args[]) { done = false; new Thread() { public void run() { try { Thread.sleep(1000); // dummy work load } catch (Exception e) { done = true; } done = true; } }.start(); while (!done); System.out.println("bye"); } } On one machine, it prints "bye" and exits right away, while on another machine, it doesn't print anything and sits there forever. Why? 回答1: This is because

Best way to reuse a Runnable

痴心易碎 提交于 2020-01-13 11:35:09
问题 I have a class that implements Runnable and am currently using an Executor as my thread pool to run tasks (indexing documents into Lucene). executor.execute(new LuceneDocIndexer(doc, writer)); My issue is that my Runnable class creates many Lucene Field objects and I would rather reuse them then create new ones every call. What's the best way to reuse these objects (Field objects are not thread safe so I cannot simple make them static) - should I create my own ThreadFactory ? I notice that

EventQueue inconsistent ID's

一曲冷凌霜 提交于 2020-01-13 11:08:10
问题 I have a problem with the following example code that shows inconsistent behavior for the EventQueue: public static void main( String[] args ) throws InvocationTargetException, InterruptedException { final long[] id1 = new long[ 1 ]; final long[] id2 = new long[ 1 ]; EventQueue.invokeAndWait( new Runnable() { @Override public void run() { id1[ 0 ] = Thread.currentThread().getId(); } } ); Thread.sleep( 5000 ); EventQueue.invokeAndWait( new Runnable() { @Override public void run() { id2[ 0 ] =

How can I limit angular $q promise concurrency?

£可爱£侵袭症+ 提交于 2020-01-13 10:12:13
问题 How do I do something like $q.all but limiting how many promises are executed concurrently? My question is just like How can I limit Q promise concurrency? I want no more than 5 process spawned at a time The accepted answer for that other question is a library written for promise wrapped to work with Q. But I'm interested specifically in a solution for Angular's $q rather than for Q . Background: The problem being solved: I have a bunch of files to download in 2 steps: a) Get URL b) download