Quartz Cluster Enhancement_00.How to use?
Reproduced with attribution/funnyzpc/p/18540378
open source address/funnyzpc/quartz
Basic structure of a table
In general the configuration and development of the tasks basically follows the basic relationship of the table in the figure above, except for the app
as well asnode
The configuration needs to be done manually, except for theapp
up tonode
is automatically generated when the executable is started.app
as well asnode
data ~
Rear Tube Configuration
Let's start with the basic page of the back tube~
on account ofapp
together withnode
It's a one-to-many relationship, so here it goes under one page:
-
Here's what needs to be said
app
together withnode
Generally there is no need to add a new one, if in special cases please refer to the following figure:
app additions
node added
on account ofnode
Must be associated with an existingapp
You can only add new entries, which are available in theapp list
center
In addition, it should be noted that.
-
If the executing side can't get the host
host IP
as well asHost Name
will randomly generate a same-namedhost IP
as well asHost Name
At this point, it makes no sense to add them manually on the admin sideremoving
-
To delete an application you must first delete the node associated with the application (
node
), a node being deleted prevents the node's corresponding execution side from executing its tasks, and deleting the application also -
Deleting an application or a node does not change the state of tasks and executables, nor does it delete tasks and executables. Executables without a node are not executed and are periodically cleaned up.
Enable/Disable
Enable and disable only operate on nodes or applications, disabling a node prevents all tasks under the node from executing, disabling an application prevents all nodes associated with the application from executing tasks, and this operation does not change the tasks or executables~.
Take a look at the node task and execution configuration again.
Task/execution configuration is the main task of the management side, the execution configuration using the associated task configuration (PID) associated with the corresponding task (job), the execution item (execute) is not independent of the existence!
New Task Configuration
-
The application name/scheduling name is the automatically or manually configured
Application Information
The task state can only have initialization at configuration time (INIT
)/normal execution (EXECUTING
), if you don't want to execute it immediately, choose Initialize (INIT
)Added Execute Config-CRON time task
-
The task type can only be a simple task (SIMPLE) or a task with a time item of expression (CRON), with both types of execution configured (
execute
) Filling in the fields will make a difference
CRON mission(used form a nominal expression)CRON expression
is required, and the default time zone at this stage isAsia/Shanghai
, which will be changed to get the default from the system.Starting time
Generally do not fill in the default is -1, the new submission is based on the current time to replenish theend time
is also non-required, the end time is also -1 by default, the end time if -1 will be added to the last execution time after the last execution of the taskAdded Execute Configuration-SIMPLE Time Tasks
-
The circled fields in the chart are required, and it should be noted that if the
Implementation end time
together withNumber of executions
All set, specific tasks will be executed according to the smallest limit for the actual execution, such as set the end of a long time but the number of times to execute only a few times, then the final probability will only be the number of times to execute the limit for executionAdditionally, for execution configurations, when execution is complete, the corresponding
Execute Configuration
Delete only, do not modify or stop, has been completed for such operations is meaningless, rather than adding a new execution configuration
Console Development Configuration and Integration
Here is an example of springboot only:
- Add a dependency, if you have a maven private service, it is recommended that you put it in the private service.
<dependency>
<groupId></groupId>
<artifactId>quartz-client</artifactId>
<version>2.3.2</version>
<!-- This is a local introduction,Suggested to be put into private service-->
<scope>system</scope>
<systemPath>${}/src/main/resources/lib/quartz-client-2.3.</systemPath>
</dependency>
- Startup classes need to exclude auto-assembly
// This line is the kicker!
@SpringBootApplication(exclude = {})
public class MeeAdminApplication {
/**
* Logging
*/
private static final Logger LOG= ();
public static void main(String[] args)throws Exception {
ConfigurableApplicationContext application = (, args);
Environment env = ();
String ip = ().getHostAddress();
String path = ("-path"); String
("\n\t----------------------------------------------------------\n\t" +
"Application MeeAdminApplication is running!\n\t" +
"Local: \t\thttp://localhost:" + port + path + "/\n\t" +
"External: \thttp://" + ip + ":" + port + path + "/\n\t" +
"----------------------------------------------------------");
}
}
- An instance needs to be configured to use the
@Service
public final class QrtzJobServiceImpl implements QrtzJobService {
/**
* log (computing)
*/
private static final Logger LOG = ();
/**
* quartztimed taskapi
*/
private final Scheduler scheduler;
public QrtzJobServiceImpl(DataSource dataSource) {
= new StdScheduler(dataSource);
}
}
- Calling the sdk
@Override
public MeeResult<Integer> updateJobState(String job_id,String state) {
Object[] result = (job_id,state);
int updateCount = (int)result[0];
if(updateCount>0){
return (updateCount);
}else{
return ((String)result[1]);
}
}
Scheduler provides a wide variety of api's, note the difference between some of the interfaces:
in the event thatmanagement side
together withexecutive side
All-in-one There is no need to introduce a client dependency (quartz-client
), and there is no need to exclude auto-assembly from the startup class (QuartzAutoConfiguration
), and you don't need to pass in a database using the sdk constructor, just this.
@Autowired
private Scheduler scheduler;
Execution-side development configuration and integration
- Introducing dependencies while excluding native Quartz
<dependency>
<groupId></groupId>
<artifactId>spring-boot-starter-quartz</artifactId>
<version>${}</version>
<exclusions>
<exclusion>
<groupId>-scheduler</groupId>
<artifactId>quartz</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId></groupId>
<artifactId>quartz-core</artifactId>
<version>2.3.2</version>
<!-- This is a local introduction,Suggested to be put into private service-->
<scope>system</scope>
<systemPath>${}/src/main/resources/lib/quartz-core-2.3.</systemPath>
</dependency>
- Adding Dependencies
### ----------- quartz ------------------
-store-type=jdbc
=
=6000
= =true
=true
# Table name prefix
=QRTZ_
=${}
#=
==
# Thread count configuration
=10
=5
# Thread inheritance context class loader for initialization threads
=true
# Whether to enable pessimistic lock to control trigger concurrency in the cluster
=true
Inside the configuration item, pay attention to the number of threads, if you are using theMeeThreadPool
imitatethreadCount
is the maximum number of threads, the number of core threadsthreadCount-2
The minimum number of CPU cores is 2, depending on the actual number of CPU cores and whether it is IO-intensive or CPU-intensive.
secondly, it is important to note thattablePrefix
If the table name has been changed, the changed table name will be used.prefix (linguistics)
Just configure it.
- Define a task
- If you are using the
spring
offeredQuartzJobBean
to develop:
import ; import ; import ; import ; import org.; import org.; import ; import ; import ; public class ATestJob extends QuartzJobBean { private static final Logger log = (); @Override protected void executeInternal(JobExecutionContext context) throws JobExecutionException { try { ("===>ATestJob::executeInternal {}-{} : {}-{}<===" ,(),(),(),()); } catch (Exception e) { throw new JobExecutionException(e); } } }
- If you are using the
Quartz
offeredJob interface
to develop, also available:
import ; import ; import ; import ; import org.; import org.; import ; public class Job01TestService implements Job { private static final Logger LOGGER = (); @Override public void execute(JobExecutionContext context) throws JobExecutionException { ("=>>{}-{}.{}-{}",(),(),(),()); } }
- If you are using the
Both of the above are possible, and it is important to note that whether you inherit theQuartzJobBean
or an implementation of ``Job, there is no need to make the class famous as aspring
bean
Classes (@Service
or @Component
),Quartz
The internal self-creates the task class asspring bean
~
Development Notes
- utilization
quartz-client
Added tasks are generally most likely to be added at the end of the5 seconds.
is executed after that, because task polling is5 seconds.
poll - The executing side performs an exception (
Quartz
non-operational) tasks at the latest in the15S
Resume task execution afterward, since cluster/default fire handling is15 seconds.
poll - Added tasks are noted if they are not executed first
Configuration item is configured or not, this configuration item corresponds to the
app
tabulatedapplication
field - Actual tasks with logs showing task delays are recommended for troubleshooting.
hosting resources
Whether it is occupied or not, orNumber of threads
Is the configuration reasonable