samedi 16 mai 2015

Synchronization and @Transactional confuses me

I read about transaction management in spring using @Transactional annotation in our service methods or on service class and configuring our transaction with its propagation, isolation, timeout, readOnly attributes. Now my question is:

1) Do we still need to use synchronization (using synchronized keyword) or multi-threading if we are using @Transactional appropriately to achieve ACID properties?

2) What could be the different scenarios to still use java multi-threading in our JEE web-application?

3) If multi-threading is required, what layer of our application should be using synchronized methods or blocks for better performance ?

I'm learning with the help of a dummy Online Banking project which I found in github. So it would be nice if the answers are connected to this scenario. So here are my classes (just to give you a idea):

//Here are some entity classes

@Entity public class User{...}

@Entity pulic class Account{...}

@Entity public class Card{...}

@Entity public class Operation{...}

// now some DAO examples

public class OperationDaoImpl implements OperationDao {

Page findNonCardByAccountIdAndYearMonth(Integer accountId, YearMonth yearMonth, Pageable pageable){...}

Page findTransferByAccountId(Integer accountId, Pageable pageable){...} DateTime getLastOperationDate(){...}

}

// now some service examples

@Service

@Transactional(readOnly = true)

@Validated

public class BankServiceImpl implements BankService {

public Map sumResolvedCardOperationsByAccountIdAndYearMonth(Integer accountId, YearMonth yearMonth) {...}

@Transactional(readOnly = false)

public void performTransfer(Integer debitedAccountId, Integer creditedAccountId, @Min(10) BigDecimal amount) throws UnsufficientBalanceException {...}

}

// and there are spring-mvc controllers.

Guys! sorry for making this question this long. Any kind of suggestion is welcome. Thanks.

Aucun commentaire:

Enregistrer un commentaire