-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix($Quartz): correct
StackOverflowError
from inappropriate Hutool …
…usage
- Loading branch information
1 parent
1021551
commit ae086dc
Showing
15 changed files
with
433 additions
and
501 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
...loud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/GreetingBean.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/GreetingBean.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.jmsoftware.maf.springcloudstarter.quartz | ||
|
||
import com.jmsoftware.maf.common.util.logger | ||
import com.jmsoftware.maf.springcloudstarter.property.MafProjectProperties | ||
import com.jmsoftware.maf.springcloudstarter.quartz.annotation.QuartzSchedulable | ||
import org.springframework.stereotype.Component | ||
|
||
/** | ||
* Description: GreetingBean, demo for dynamic Quartz job, which is configured in the table `quartz_job_configuration`. | ||
* | ||
* @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 7/13/2021 10:16 PM | ||
* @see [Quartz Scheduler](https://docs.spring.io/spring-boot/docs/current/reference/html/features.html.features.quartz) | ||
*/ | ||
@Component("greetingBean") | ||
class GreetingBean( | ||
private val mafProjectProperties: MafProjectProperties | ||
) { | ||
companion object { | ||
val log = logger() | ||
} | ||
|
||
@QuartzSchedulable | ||
@Suppress("unused") | ||
fun hello() { | ||
log.info( | ||
"Greeting from Quartz job, current service is: {}", | ||
mafProjectProperties!!.projectArtifactId | ||
) | ||
} | ||
} |
79 changes: 0 additions & 79 deletions
79
...arter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/QuartzConfiguration.java
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
...starter/src/main/java/com/jmsoftware/maf/springcloudstarter/quartz/QuartzConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.jmsoftware.maf.springcloudstarter.quartz | ||
|
||
import com.jmsoftware.maf.common.util.logger | ||
import com.jmsoftware.maf.springcloudstarter.property.MafProjectProperties | ||
import com.jmsoftware.maf.springcloudstarter.quartz.controller.QuartzJobConfigurationController | ||
import com.jmsoftware.maf.springcloudstarter.quartz.service.QuartzJobConfigurationService | ||
import com.jmsoftware.maf.springcloudstarter.quartz.service.impl.QuartzJobConfigurationServiceImpl | ||
import org.quartz.Scheduler | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass | ||
import org.springframework.boot.autoconfigure.quartz.QuartzAutoConfiguration | ||
import org.springframework.boot.autoconfigure.quartz.QuartzProperties | ||
import org.springframework.boot.autoconfigure.quartz.SchedulerFactoryBeanCustomizer | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.scheduling.quartz.SchedulerFactoryBean | ||
import org.springframework.transaction.PlatformTransactionManager | ||
import java.util.* | ||
|
||
/** | ||
* # QuartzConfiguration | ||
* | ||
* Description: QuartzConfiguration, change description here. | ||
* | ||
* @author Johnny Miller (锺俊), e-mail: johnnysviva@outlook.com, date: 4/15/22 7:19 PM | ||
* @see QuartzAutoConfiguration | ||
*/ | ||
@ConditionalOnClass(Scheduler::class, SchedulerFactoryBean::class, PlatformTransactionManager::class) | ||
class QuartzConfiguration( | ||
private val mafProjectProperties: MafProjectProperties | ||
) { | ||
companion object { | ||
private val log = logger() | ||
} | ||
|
||
@Bean | ||
fun schedulerFactoryBeanCustomizer(quartzProperties: QuartzProperties): SchedulerFactoryBeanCustomizer { | ||
val cpuCoreCount = Runtime.getRuntime().availableProcessors() | ||
val threadCount = (2 * cpuCoreCount).toString() | ||
quartzProperties.properties[SchedulerFactoryBean.PROP_THREAD_COUNT] = threadCount | ||
return SchedulerFactoryBeanCustomizer { schedulerFactoryBean: SchedulerFactoryBean -> | ||
schedulerFactoryBean.setQuartzProperties(asProperties(quartzProperties.properties)) | ||
log.warn("Quartz thread pool enhanced by current cpuCoreCount: $cpuCoreCount, threadCount: $threadCount") | ||
schedulerFactoryBean.setSchedulerName("${mafProjectProperties.projectArtifactId}-quartz-scheduler") | ||
schedulerFactoryBean.setWaitForJobsToCompleteOnShutdown(true) | ||
schedulerFactoryBean.setBeanName("schedulerFactoryBean") | ||
} | ||
} | ||
|
||
private fun asProperties(source: Map<String, String>): Properties { | ||
val properties = Properties() | ||
properties.putAll(source) | ||
return properties | ||
} | ||
|
||
@Bean | ||
fun greetingBean(): GreetingBean { | ||
log.warn("Initial bean: `${GreetingBean::class.java.simpleName}`") | ||
return GreetingBean(mafProjectProperties) | ||
} | ||
|
||
@Bean | ||
fun quartzJobConfigurationController( | ||
quartzJobConfigurationService: QuartzJobConfigurationService | ||
): QuartzJobConfigurationController { | ||
log.warn("Initial bean: `${QuartzJobConfigurationController::class.java.simpleName}`") | ||
return QuartzJobConfigurationController(quartzJobConfigurationService) | ||
} | ||
|
||
@Bean | ||
fun quartzJobConfigurationService(schedulerFactoryBean: SchedulerFactoryBean): QuartzJobConfigurationService { | ||
log.warn("Initial bean: `${QuartzJobConfigurationServiceImpl::class.java.simpleName}`") | ||
return QuartzJobConfigurationServiceImpl(schedulerFactoryBean, mafProjectProperties) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.