multithreading

Are method References as method parameters thread safe in Java

不羁岁月 提交于 2020-05-16 08:57:46
问题 i have the following scenario: interface ValueBinding<T> { public void setValue(T input); } public enum FacesBinding { VALUE; public void bindString(ValueBinding<String> fcn, HttpServletRequest req, String param){ try { String val = req.getParameter(param); if( val != null ) fcn.setValue(val); } catch (Exception e) { } } public void bindBoolean(ValueBinding<Boolean> fcn, HttpServletRequest req, String param){ try { fcn.setValue(req.getParameter(param) != null); } catch (Exception e) { } }

Spring batch multithreading using partitioning

坚强是说给别人听的谎言 提交于 2020-05-16 07:03:56
问题 My problem statement is that- I have to pass multiple numbers of files to spring batch reader and reader runs in parellel.if we use grid-size = 100 then there will be 100 threads which is not logical. what is the way to solve this issue i.e. process many files with limited number of threads. @Bean public Step orderStep1() throws IOException { return stepBuilderFactory.get("orderStep1") .partitioner("slaveStep", partitioner()) .step(slaveStep()) .gridSize(100) .taskExecutor(taskExecutor())

Spring batch multithreading using partitioning

99封情书 提交于 2020-05-16 07:02:45
问题 My problem statement is that- I have to pass multiple numbers of files to spring batch reader and reader runs in parellel.if we use grid-size = 100 then there will be 100 threads which is not logical. what is the way to solve this issue i.e. process many files with limited number of threads. @Bean public Step orderStep1() throws IOException { return stepBuilderFactory.get("orderStep1") .partitioner("slaveStep", partitioner()) .step(slaveStep()) .gridSize(100) .taskExecutor(taskExecutor())

Keep threads alive even if console app exits

筅森魡賤 提交于 2020-05-15 10:36:24
问题 I have a console app in C# that runs endlessly and looks something like this: class Program { static void Main(string[] args) { while(true) { var listOfIds = GetItemIds(); Parallel.ForEach(listOfIds, new Parallel { MaxDegreeOfParallelism = 15}, th => DoWork(th)); Console.WriteLine("Iteration Complete"); } } static void DoWork(int id) { //do some work and save data } static List<int> GetItemIds() { //return a list of ints } } While a thread is in DoWork , it is processing data, modifying it

Keep threads alive even if console app exits

断了今生、忘了曾经 提交于 2020-05-15 10:36:11
问题 I have a console app in C# that runs endlessly and looks something like this: class Program { static void Main(string[] args) { while(true) { var listOfIds = GetItemIds(); Parallel.ForEach(listOfIds, new Parallel { MaxDegreeOfParallelism = 15}, th => DoWork(th)); Console.WriteLine("Iteration Complete"); } } static void DoWork(int id) { //do some work and save data } static List<int> GetItemIds() { //return a list of ints } } While a thread is in DoWork , it is processing data, modifying it

Implement RemoveAll on AsyncObservableCollection

非 Y 不嫁゛ 提交于 2020-05-15 10:10:12
问题 I'm trying to implement the RemoveAll on AsyncObservableCollection , this class was created for edit the collection on another thread, the structure is this: public class AsyncObservableCollection<T> : ObservableCollection<T> { private readonly SynchronizationContext _synchronizationContext = SynchronizationContext.Current; public AsyncObservableCollection() { } public AsyncObservableCollection(IEnumerable<T> list) : base(list) { } private void ExecuteOnSyncContext(Action action) { if

Implement RemoveAll on AsyncObservableCollection

让人想犯罪 __ 提交于 2020-05-15 10:09:11
问题 I'm trying to implement the RemoveAll on AsyncObservableCollection , this class was created for edit the collection on another thread, the structure is this: public class AsyncObservableCollection<T> : ObservableCollection<T> { private readonly SynchronizationContext _synchronizationContext = SynchronizationContext.Current; public AsyncObservableCollection() { } public AsyncObservableCollection(IEnumerable<T> list) : base(list) { } private void ExecuteOnSyncContext(Action action) { if

Multithreaded Perl script leads to broken pipe if called as a Python subprocess

浪尽此生 提交于 2020-05-15 09:36:10
问题 I am calling a Perl script from Python 3.7.3, with subprocess. The Perl script that is called is this one: https://github.com/moses-smt/mosesdecoder/blob/master/scripts/tokenizer/tokenizer.perl And the code I am using to call it is: import sys import os import subprocess import threading def copy_out(source, dest): for line in source: dest.write(line) num_threads=4 args = ["perl", "tokenizer.perl", "-l", "en", "-threads", str(num_threads) ] with open(os.devnull, "wb") as devnull: tokenizer =

Reusing Tensorflow session in multiple threads causes crash

柔情痞子 提交于 2020-05-15 05:52:05
问题 Background: I have some complex reinforcement learning algorithm that I want to run in multiple threads. Problem When trying to call sess.run in a thread I get the following error message: RuntimeError: The Session graph is empty. Add operations to the graph before calling run(). Code reproducing the error: import tensorflow as tf import threading def thread_function(sess, i): inn = [1.3, 4.5] A = tf.placeholder(dtype=float, shape=(None), name="input") P = tf.Print(A, [A]) Q = tf.add(A, P)

Python Multiprocessing on List of dictionaries

*爱你&永不变心* 提交于 2020-05-15 02:57:07
问题 I have a list of dictionaries. list_of_dict = [{'name' : 'bob', 'weight': 50}, {'name' : 'ramesh', 'weight': 60}] I want to process both the dictionaries at the same time What should I use for this multiprocessing Pool or Process ? 回答1: I have tried with Multiprocessing Pool from multiprocessing.pool import ThreadPool as Pool pool_size = 5 def worker(item1, itme2): try: print(item1.get('weight')) print(itme2) except: print('error with item') pool = Pool(pool_size) items = [{'name' : 'bob',