A method to solve the intermittent triggering problem of multiple transactions in different timing zones using multithreading

Source: Internet
Author: User
1. Background

One such problem needs to be addressed in the project: There are two transactions that need to be triggered every few seconds, but two transactions are performed only within the specified time zone. For example, at eight to six o'clock in the morning for office hours, two transactions must be executed every few seconds during this time period, and stop working after work.

2. Ideas

At the beginning of the question, I wanted to use a timer to solve the problem, that is, to do two timer, a timer to control a transaction, and then execute within the corresponding time zone of each transaction.

However, given that the timer is executed in the main thread, thread is executed in its own threads, and it is more efficient to use thread in multi-core multithreaded CPUs. and later transactions become more, control more complex, with the timer is not very conducive to expansion. So we finally decided to use multithreading to solve the problem.

After thinking and refer to similar cases such as http://www.cnblogs.com/shuang121/archive/2012/07/05/2578033.html, the framework is finally structured as follows:

3. Concrete implementation of 3.1 Ishedulerjob

3.2 Job

3.3SchedulerConfiguration

3.4Scheduler

3.5 Viewer

4. Optimization

A. Two transactions are related to the database of the majority of the deletion and modification, in order to ensure the uniqueness of the data, the database operations to take a transactional operation.

B. To avoid duplicate connections and shutdowns of the database, use the long connection of the database as much as possible. At the same time, in order to avoid the problem of sharing a database connection between two transactions, we specifically use a simple database connection pool for processing.

C. For the connection pool to be shared, simple interest mode is performed on the connection pool's class.

A method to solve the intermittent triggering problem of multiple transactions in different timing zones using multithreading

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.