[Solved] Multi-tasking with Multiprocessing or Threading or Asyncio, depending on the Scenario

So off the top of my head you can look at 2 things. 1) Asyncio (be careful this example uses threading and is not thread safe specifically the function asyncio.gather) import asyncio for work in [1,2,3,4,5]: tasks.append(method_to_be_called(work)) results = await asyncio.gather(*tasks) 2) Asyncio + multiprocessing https://github.com/jreese/aiomultiprocess 1 solved Multi-tasking with Multiprocessing or Threading or Asyncio, … Read more

[Solved] What is the use of join(long milliseconds) over sleep(long milliseconds) in Thread [duplicate]

Assuming you have one thread: use sleep(timeout) – it will always wait timeout seconds before continuing. Assuming you have two threads: Option 1: Thread1 simply should wait and has nothing to do with Thread2 – use sleep(timeout) – it will always wait timeout seconds before continuing. Option 2: Thread1 does have something to do with … Read more

[Solved] Can someone help me answer to this question [closed]

Depending on hardware with Hyperthreading 1 core would support 2 threads. So you will have a total of 4 threads supported by your cpu. Probably the answer will be aproximaty 25(even with hyperthreading it does not run exactly 2 times faster). Without hyperthreading 50 6 solved Can someone help me answer to this question [closed]

[Solved] Java – Thread.join( ) does not release the lock

That’s because Thread.join() doesn’t release any locks. You’ve designed a perfectly working deadlock, where Thread-1 is waiting for Thread-2 to die having locked on Foo, and Thread-2 is waiting to lock on Foo. (Technically speaking the current implementation does release locks, as it uses internally wait() while synchronized on Thread. However that’s an internal mechanism … Read more

[Solved] how to use async and await on a method that is time comsuming [closed]

To be able to await MyTimeConsumingTask it must be declared to return a Task. public async Task<SimeType> MyTimeConsumingTask() Since you said it does some network IO, you can rewrite it using async NW IO methods and then await it as var MyResult = await MyTimeConsumingTask(MyClassProperty); But in your case the simplest approach seems to be … Read more

[Solved] What is wrong with it?

The thread you create in main invokes MyThread#k() which goes into a wait. At that point, that thread will do nothing else until it is awakened or interrupted. But the only place in your code where it could possibly be awakened is the notify in MyThread#m(). Since nothing in your program calls that method, the … Read more

[Solved] Thread.sleep vs Timers

Thread.sleep which stops all processing, so what if you had a loop inside it, and what if this loop was comparing identical objects? Would it keep creating a new instance of this loop?, and if it does what is the end result, say, if it was processing some heavy duty instructions in that loop? no, … Read more

[Solved] Printing a statement using threads in Java [closed]

I think your problem is in this method: synchronized void PrintMsg(String msg) { System.out.println(msg); try { wait(); } catch (InterruptedException e) { System.out.println(“Exception”); } System.out.println(msg); notify(); } The thread that call it are going to call wait() which causes them to wait indefinitely for someone to call notify(). But there are no other calls to … Read more

[Solved] I want to Thread and Form work together [closed]

Button1Click is stopping the execution of the main thread for 3 seconds. During the sleep(3000) execution, no GDI message is processed, so the dialog boxes are NOT displayed immediately. In fact, TCustomThread.doProc works as expected, but the dialog box is not displayed until the GDI messages are processed. You have to change this method e.g. … Read more