synchronisierte Methode oder Frühling @transactional verwenden?

Ich habe eine Methode, die zum Versenden von E-Mails verwendet wird. Ich möchte diese Methode sperren, so dass nur ein Thread es pro Zeit und den Rest Pool gleichzeitig zugreifen kann. Soll ich die Methode synchronisieren oder spring @transactional PROPAGATION_REQUIRED verwenden?

in meiner Serviceschicht
 //each time use new thread to send out email
  public  void sendThroughSMTP(List<String> emails,String subject,String content){

            //each time will open and sent through port 25.  dont u think this will caused too many threads spawned?
            BlastEmailThread blastEmailThread = new BlastEmailThread(emails,subject,content);

            blastEmailThread.start();


}

Antworten auf die Frage(6)

Ihre Antwort auf die Frage