Answer the question
In order to leave comments, you need to log in
Synchronization of methods or do everything in one method (multithreaded programming)?
I'm using Spring AMQP for messaging and queuing image and video processing.
@Transactional
@RabbitListener(queues = "test")
public void processImage(Message message, @Header("image_id") long imageId,
@Header("account_id") long accountId) throws Exception {
Image image = imageService.getImage(imageId);
byte[] renderedImageBuffer = null;
String format = ImageUtils.getImageFormat(message.getBody());
switch (format.toLowerCase()) {
case "jpeg":
renderedImageBuffer = message.getBody();
break;
case "png":
renderedImageBuffer = ImageUtils.convertPNGtoJPEG(message.getBody());
break;
}
image.setWidth(image.getBufferedImage().getWidth());
image.setHeight(image.getBufferedImage().getHeight());
image.setData(renderedImageBuffer);
imageService.updateImage(image);
Image avatar = ImageUtils.scaleImage(image, 35, 35);
avatar.setFileName("fss_avatar" + accountId);
imageService.saveImage(avatar);
Account account = accountService.getAccount(accountId);
account.setAvatar(avatar);
accountService.updateAccount(account);
}
@Bean
public SimpleRabbitListenerContainerFactory container() {
SimpleRabbitListenerContainerFactory container = new SimpleRabbitListenerContainerFactory();
container.setConnectionFactory(connectionFactory);
container.setConcurrentConsumers(20);
container.setMaxConcurrentConsumers(30);
container.setChannelTransacted(true);
container.setTransactionManager(transactionManager());
return container;
}
(ImageUtils)
. Should I shove all the methods into the message handler or make the methods of the utility class synchronized? On the one hand, with the first method there is less hassle, but on the other hand, the code will become unreadable. In which case will the performance be greater?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question