making program to send mail by different threads at the same time through parallel processing

后端 未结 2 1188
無奈伤痛
無奈伤痛 2021-01-24 03:43

I have the below program which send the mail using java mail api , now this the is the simple program i have developed now i want to modify in terms of parallel execution by usi

2条回答
  •  隐瞒了意图╮
    2021-01-24 04:09

    I think you would use a ScheduledExecutorService and call it like this.

    ScheduledExecutorService exec = Executors.newScheduledThreadPool(amount);
    for (int i = 0; i < amount; i++) {
        exec.schedule(yourMailSendingRunnable, delay, TimeUnit.MILLISECONDS);
    }
    

    You should replace amount, yourMailSendingRunnable and delay to account for your needs.

提交回复
热议问题