lundi 20 avril 2015

Spring Executors - Executing method in thread with specific index

In my application I have a receiver which should processing messages with many threads. Sender module is putting messages on stack and receiver module is taking it from this stack. Everything works with two threads (one for sending, one for receiving). Now I want to receive messages with many threads.

Messages have some kind of group number. I need to process one group of messages in one thread (there will be more messages groups than threads). How can I handle with this?

I want to do something like this:

public class ReceiverExample {
    @Autowired
    Receiver receiver; 

    @Autowired 
    TaskExecutor executor;

    public void receive(){
        Msg msg = receiver.receive(); 
        int index = msg.getIndex();

        executor.execute(
                //put index ? ,
                msg
        );
    }
}

I'm using Spring Framework. I know I must use some kind of executor, but I can't find any good example showing my problem.

Aucun commentaire:

Enregistrer un commentaire