Java Implementation High concurrency Api--service Layer 2

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.