A method that uses multithreading to solve the problem of intermittent triggering in different time zones of multiple businesses.

Source: Internet
Author: User
Tags time zones

A method that uses multithreading to solve the problem of intermittent triggering in different time zones of multiple businesses.
1. Background

The project needs to solve the following problem: two services must be triggered every few seconds, but both services only perform this action within the specified time range. For example, during the period from AM to AM, the two businesses must be executed every few seconds, and work stops after work.

2. Ideas

At first, I wanted to use timer to solve this problem. That is, I made two timers, one timer to control one transaction, and then executed in the corresponding time zone of each transaction.

However, considering that Timer is executed in the main Thread and Thread is executed in its own Thread, the efficiency of using Thread in multi-core and multi-Thread CPUs is higher. In addition, as the number of transactions increases in the future, the control is more complex, and timer is not very conducive to expansion. So we finally decided to use multithreading to solve this problem.

After thinking about and referring to similar cases, such as explain:

3. Implementation of IshedulerJob 3.1

 

3.2 Job

 

3.3 SchedulerConfiguration

 

3.4 Scheduler

 

3.5 viewer

 

4. Optimization

A. Both transactions involve the addition, deletion, query, and modification of multiple data in the database. To ensure data uniqueness, transaction operations are performed on the database.

 

B. To avoid repeated connections and shutdown of the database, try to use persistent connections of the database here. At the same time, in order to avoid the problem that two transactions share one database connection, we specially use a simple database connection pool for processing.

 

C. In order for the connection pool to be shared, perform the singleton mode for the class in which the connection pool is located.

 

 

Related Article

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.