I am not really familiar with modern java, but I have a GRPC server that receives a bunch of information which need to be pair together and then trigger a sequence of events. I would like to have my Service store the first piece of information and then once the 2nd info comes in trigger an event or thread. I am not sure the best way to do this? I was looking at settableFuture, but wondering if people have a good library or design that I should be using for this.
CodePudding user response:
As written, the question describes a simple stateful class pattern. With GRPC, you implement the operations as methods in a class, so adding a field to the class to keep track of that state can do the job.
Additional specifics depend on some of the GRPC details, and how the server will process the requests.
CodePudding user response:
For threads that need to run at certain times or based on certain triggers, the following classes are very helpful.
Executors, Executor Service
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/Executors.html
Runnable
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Runnable.html
You should also store the "information" you mention in a thread-safe class, for example a ConcurrentHashMap.