Java – remove blocking from method

This is homework

I don't want a solution, just a few links or ideas@ H_ 502_ 3@

In short, what I want to do is @ H_ 502_ 3@

Simple example: @ h_ 502_ 3@

public class Example
{
    public void method()
    {
           int x = doThat();
           //Call other methods which do not depend on x
           return;
    }
}

Dothat() is a known time - consuming method, which can cause the program to block until the result is returned I want to use different methods of this object, but the program will be frozen until dothat() is completed These different methods do not have to be called from the method () used in this example, but may come from outside the object@ H_ 502_ 3@

I've thought about using threads, but if I have a large number of objects (1000), this may not be very effective (correct me if I'm wrong) I think if I use threads, I have to use one thread for each object@ H_ 502_ 3@

Besides calling dothat(), is there any other method for the thread that can make the calling object not blocked? If threads are the only way, can you provide links@ H_ 502_ 3@

Knowing that such a question has been voted on, I will accept any downvotes But please just a link will be great@ H_ 502_ 3@

Thank you in advance I hope the problem meets the rules@ H_ 502_ 3@

Solution

I can also use threads, but I just want to add that look at Java util. concurrent. Executors (create thread pool because you have many objects) and Java Util can be fun concurrent. Future and Java util. concurrent. Callable classes that allow you to start threads that return values

See concurrency tutorial for more information@ H_ 502_ 3@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>