在搜索了很多有关Java的内容后,我对以下问题感到非常困惑:
Why would I choose an asynchronous method over a multi-threaded method?
Java futures are supposed to be non-blocking. What does non-blocking mean? Why call it non-blocking when the method to extract information from a
Future
--i.e.,get()
--is blocking and will simply halt the entire thread till the method is done processing? Perhaps a callback method that rings the church bell of completion when processing is complete?How do I make a method async? What is the method signature?
public List<T> databaseQuery(String Query, String[] args){ String preparedQuery = QueryBaker(Query, args); List<int> listOfNumbers = DB_Exec(preparedQuery); // time taking task return listOfNumbers; }
How would this fictional method become a non blocking method? Or if you want please provide a simple synchronous method and an asynchronous method version of it.