multithreading

Java error with a PrintWriter [duplicate]

老子叫甜甜 提交于 2020-01-16 22:01:06
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 4 years ago . I have this code to connect a server with a client, i need send json objects to a android studio client but the method escribir in the line of the printwriter have a error, and i dont konw what is the problem, please see the code and help me public class Servidor { ServerSocket servidor=null; Socket socket=null; BufferedReader lector=null; PrintWriter escritor=null;

Java error with a PrintWriter [duplicate]

。_饼干妹妹 提交于 2020-01-16 21:58:25
问题 This question already has answers here : What is a NullPointerException, and how do I fix it? (12 answers) Closed 4 years ago . I have this code to connect a server with a client, i need send json objects to a android studio client but the method escribir in the line of the printwriter have a error, and i dont konw what is the problem, please see the code and help me public class Servidor { ServerSocket servidor=null; Socket socket=null; BufferedReader lector=null; PrintWriter escritor=null;

Rust - Pass a function reference to threads

断了今生、忘了曾经 提交于 2020-01-16 19:35:48
问题 Say I have a struct like: pub struct MyStruct { f: Arc<dyn Fn(Vec<f64>) -> Vec<f64>>, } impl MyStruct { pub fn new(f: Arc<dyn Fn(Vec<f64>) -> Vec<f64>>) -> MyStruct { MyStruct { f } } pub fn start(&self) { for _ in 0..5 { let f = self.f.clone(); thread::spawn(move || { let v: Vec<f64> = get_random_vector(); let v = (f)(v); // do something with v }); } } } I'm getting an error that the function cannot be shared between threads safely since the dyn Fn(Vec<f64>) -> Vec<f64>) type doesn't

Embedded Python: Multiple Sub-Interpreters not working

99封情书 提交于 2020-01-16 19:35:08
问题 I'm trying to understand sub-interpreters and GIL. But my experiment is failing often(The same code rarely works). Gathering info from SO questions and few sites, I have the following code which spawns 2 non-python threads. Each of these threads are given a python sub-interpreter. I want to release GIL inside these threads and call a DLL function in C++(though this example does not detail that. Here I just write to stdout). Basically I want to see concurrency in the execution(Non-Python DLL

WPF/WCF Async Service Call and SynchronizationContext

天涯浪子 提交于 2020-01-16 19:25:10
问题 I have a feeling there's got to be a better solution than what I've come up with; here's the problem: A WPF form will call a WCF method, which returns a bool. The call itself should not be on the UI thread, and the result of the call will need to be displayed on the form, so the return should be marshaled back on to the UI thread. In this example I created a "ServiceGateway" class, to which the form will pass a method to be executed upon completion of a Login operation. The gateway should

WPF/WCF Async Service Call and SynchronizationContext

北慕城南 提交于 2020-01-16 19:24:09
问题 I have a feeling there's got to be a better solution than what I've come up with; here's the problem: A WPF form will call a WCF method, which returns a bool. The call itself should not be on the UI thread, and the result of the call will need to be displayed on the form, so the return should be marshaled back on to the UI thread. In this example I created a "ServiceGateway" class, to which the form will pass a method to be executed upon completion of a Login operation. The gateway should

Call api for every 1 minute(60*1000 milliseconds) upto 10 hours

橙三吉。 提交于 2020-01-16 19:18:12
问题 I am working on the app that runs in background and need to call api for every 1 minute(60*1000 millisecond) without any fluctuations. I have tried Scheduler,timer and things but it is not working proper. For example, my scenario is to call the api on 09:11:36 am(first api call),09:12:36 am(second api call) and so on and at the end the final api call will be at 11:20:36 pm. I used below code : Handler minuteHandler = new Handler(); minuteHandler.postDelayed(runnable, 60000); final Runnable

Multithreading with overloaded member functions

别说谁变了你拦得住时间么 提交于 2020-01-16 18:50:10
问题 Compiling with $ g++ -std=c++0x -I "inc" src/*.cpp and receiving src/ProcessGroup.cpp:25:10: error: no matching constructor for initialization of 'std::__1::thread' thread t(&Process::Run, p, exit_code); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:349:9: note: candidate template ignored: couldn't infer template argument '_Fp' thread::thread(_Fp&& __f, _Args&&... __args) ^ g++ is complaining that

Threading: How to update label or close form

馋奶兔 提交于 2020-01-16 18:45:47
问题 I haven't really done much with threads before and I'm having a problem updating a label and closing a form. When debugging, the CloseDialog() sub is definitely running in the main thread so I don't understand why it's not closing. There are no loops or anything else running on the form to keep it open. I'm also having a problem updating the text on a label with information passed from another thread in real time. The AddOUToTreeView sub gets invoked and works fine, but the subs from

PHP run loop and script at same time

故事扮演 提交于 2020-01-16 18:43:11
问题 I'm currently running a loop in my PHP script to check if the user connection has been aborted (connection_aborted() does not work on ajax calls): connection_check.php : <?php ignore_user_abort(true); for ($i = 0; $i < 1000; $i++) { echo "<br>"; flush(); ob_flush(); if (connection_aborted()) { echo "nocon"; exit; } else { // Everything is fine } sleep(3); } ?> However, I also need to run the rest of my PHP code while this loop is running in the "background" so that when the connection is