• Post Reply Bookmark Topic Watch Topic
  • New Topic

Convert sync method to async method in java 1.4  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm new around here and I come with a question that has me blocked.

I need to convert a synchronous method in asynchronous and should be in java 1.4 so I can not use Executor, Future ...

The code that I have to convert this style is asynchronous:



What I need is that the call inside the loop is conducted asynchronously to avoid having to wait for the current synchronous method finishes to make another request.

I hope I explained properly because the English is not my native language.

Thank you very much in advance.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Is there a special reason why you are using Java 1.4? That is a very old version, which has not been supported for years.

Since you can't use all the nice concurrency classes that were added in Java 5, you will have to do this by programming with threads yourself. In the method, you can start a new thread to do the work. Using the 'wait', 'notify' and 'notifyAll' methods of class Object, you can make a mechanism for the main thread to wait and get the result of the asynchronous task.

If you want to make it more fancy, you could make a thread pool, but it's not easy to build a correct thread pool mechanism yourself (I've done it, long ago, I remember I had a number of difficult concurrency problems to fix).
 
Angel Muelas
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is true that java 1.4 is a delay but is the version that our customer use.

A version change is not possible.

I´ll take a look how to implement with traditional threads
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!