Today completes the entire Java implementation of high concurrency Api--service layer of learning:
1. Encoding of the interface and the logical writing of the implementation class
2. Manage service with spring IOC
3. Use spring declarative transactions to control transactions:
Transaction Main configuration:
<!--configuration Transaction Manager-
<bean id= "TransactionManager"
class= "Org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name= "DataSource" ref= "DataSource" ></property>
</bean>
<!--Configure annotation-based declarative transactions to manage transactional behavior by default using annotations--
<tx:annotation-driven transaction-manager= "TransactionManager"/>
and understand the 3 ways spring uses transactions, and ultimately decide to use declarative transactions for the following reasons:
* 1, the development team agreed to the agreement, clearly marked the style of the transaction method
* 2, ensure that the execution time of the transaction method is as short as possible, do not interspersed with other network operations, rpc/http requests or stripping out of the transaction method
* 3, not all methods require transactions, such as only one modification operation, read-only operation does not require transaction control
Finally, JUnit was used for the integration test, and the points of attention for the test were
The business logic needs to be tested after the interface method has been tested. That is, there may be 2 interfaces tested by the binding of a certain business process.
@Test
public void Testseckilllogic () {
Long id = 1001L;
exposer Exportseckillurl = seckillservice.exportseckillurl (ID);
if (exportseckillurl.isexposed ()) {
Logger.info ("exposer={}", Exportseckillurl);
Long phone = 15068751236L;
String MD5 = EXPORTSECKILLURL.GETMD5 ();
try {
seckillexectuion Executeseckill = Seckillservice.executeseckill (ID, phone, MD5);
logger.info ("result={}", Executeseckill);
} catch (Repeatkillexception e) {
Logger.error (E.getmessage ());
} catch (Seckillcloseexception e) {
Logger.error (E.getmessage ());
}
} else {
Logger.warn ("exposer={}", Exportseckillurl);
}
Java Implementation High concurrency Api--service Layer 2