Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7079997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:44:26+00:00 2026-05-28T06:44:26+00:00

I have two processes: Process 1 – implements runnable and can run forever. Process

  • 0

I have two processes:

Process 1 – implements runnable and can run forever.
Process 2 – fires at fixed hour and minute of day (i’ve created a job that run with Quartz).

To warn the process 1 that the other process is running I can use the TriggerListener, but how can I postpone the fire of the second process if the process 1 still doing something?

For example: I need to fire the trigger at 2PM, but this need to be done after 2PM if the process 1 isnt idle.

Here’s some sample:

ProcessForever.java

import static org.quartz.CronScheduleBuilder.dailyAtHourAndMinute;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

public class ProcessForever implements Runnable {

    private boolean processTwoRunning;
    private Scheduler scheduler;
    private Trigger trgProcessTwo;
    private String status;

    public static final STATUS_PROCESS = "PROCESS";
    public static final STATUS_SLEEP = "SLEEP";

    private static Logger LOGGER = Logger.getLogger( ProcessForever.class.getName() );

    public void init() throws SchedulerException {
        SchedulerFactory fact = new StdSchedulerFactory();
        scheduler = fact.getScheduler();
    }

    @Override
    public void run() {
        try {
          scheduler.start();
          buildTrigger();
          while( true ) {
              //do something and then sleep for some time.
              //the Quartz trigger should fire only in STATUS_SLEEP...
              setStatus( STATUS_PROCESS );      
              try { Thread.sleep(120 * 1000); }catch(Exception e){}
              setStatus( STATUS_SLEEP );        
          }catch( Exception e ) {
              e.printStackTrace();
          }
}

    private void buildTrigger() throws SchedulerException {
    LOGGER.info("defineCargaDadosTrigger()");
    JobDetail dt = newJob( ProcessTwo.class )
                             .withIdentity("coleta","grpcoleta")
                             .build();

    trgProcessTwo = newTrigger().withIdentity( 
                          new TriggerKey("triggerProcessTwo") )
                                  .forJob( dt )
                                  .startNow()
                                  .withSchedule( dailyAtHourAndMinute(13,31) )
                                  .build();
    KeyMatcher<TriggerKey> m = KeyMatcher.keyEquals( trgProcessTwo.getKey() );
    scheduler.scheduleJob(dt, trgProcessTwo );
    //this will notice the process 1 that the trigger is running...
            //scheduler.getListenerManager().addTriggerListener(someclass, m );
}

    //getters & setters ommited...

}

ProcessTwo.java

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
 /**
  ProcessTwo cannot run concurrent with ProcessForever...
  */
 public ProcessTwo implements Job {
      @Override
      public void execute(JobExecutionContext arg0) throws JobExecutionException {
          System.out.println("Doing something...");
          try { Thread.sleep(10000); } catch( InterruptedException i ){}
          System.out.println("Stop doing something...");
      }
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:44:27+00:00Added an answer on May 28, 2026 at 6:44 am

    That’s quite a common question in Quartz. Here are some hints provided by the FAQ

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two ASP.NET sites (they can not run in the same process) and
I have two processes - a user process and a root-level LaunchDaemon. I'd like
I have two running processes in Windows, and each process has a pipe to
I have two unrelated processes that use .NET assemblies as plugins. However, either process
We have a process that needs to run every two hours. It's a process
i have two processes so process one generate some container object and send it
I have two processes: a server that should be run in background, but starts
I have two processes which exange messages each other. Process A is a normal
i have the following Problem: i have two Processes process A which starts process
I have two processes, A and B. B is a process that performs some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.