Example usage for java.util.concurrent ScheduledExecutorService shutdown

List of usage examples for java.util.concurrent ScheduledExecutorService shutdown

Introduction

In this page you can find the example usage for java.util.concurrent ScheduledExecutorService shutdown.

Prototype

void shutdown();

Source Link

Document

Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.

Usage

From source file:ScheduledTask.java

public static void main(String[] args) {
    // Get an executor with 3 threads
    ScheduledExecutorService sexec = Executors.newScheduledThreadPool(3);

    ScheduledTask task1 = new ScheduledTask(1);
    ScheduledTask task2 = new ScheduledTask(2);

    // Task #1 will run after 2 seconds
    sexec.schedule(task1, 2, TimeUnit.SECONDS);

    // Task #2 runs after 5 seconds delay and keep running every 10 seconds
    sexec.scheduleAtFixedRate(task2, 5, 10, TimeUnit.SECONDS);

    try {//from   w  w  w. j av  a 2 s.com
        TimeUnit.SECONDS.sleep(60);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    sexec.shutdown();
}

From source file:org.dcm4che.tool.ianscu.IanSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from   w w  w.j  a va 2 s  .c o m*/
        CommandLine cl = parseComandLine(args);
        final IanSCU main = new IanSCU();
        configureIAN(main, cl);
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(main.conn, main.ae, cl);
        CLIUtils.configure(main.conn, cl);
        main.remote.setTlsProtocols(main.conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites());
        main.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        CLIUtils.addAttributes(main.attrs, cl.getOptionValues("s"));
        main.setUIDSuffix(cl.getOptionValue("uid-suffix"));
        List<String> argList = cl.getArgList();
        boolean echo = argList.isEmpty();
        if (!echo) {
            System.out.println(rb.getString("scanning"));
            DicomFiles.scan(argList, new DicomFiles.Callback() {

                @Override
                public boolean dicomFile(File f, Attributes fmi, long dsPos, Attributes ds) {
                    if (UID.InstanceAvailabilityNotificationSOPClass
                            .equals(fmi.getString(Tag.MediaStorageSOPClassUID))) {
                        return main.addIAN(fmi.getString(Tag.MediaStorageSOPInstanceUID), ds);
                    }
                    return main.addInstance(ds);
                }
            });
        }
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        main.device.setExecutor(executorService);
        main.device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            if (echo)
                main.echo();
            else
                main.sendIans();
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("ianscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("ianscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.movescu.MoveSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//w  w w  . ja  va  2s  .c  o m
        CommandLine cl = parseComandLine(args);
        MoveSCU main = new MoveSCU();
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(main.conn, main.ae, cl);
        CLIUtils.configure(main.conn, cl);
        main.remote.setTlsProtocols(main.conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites());
        configureServiceClass(main, cl);
        configureKeys(main, cl);
        main.setPriority(CLIUtils.priorityOf(cl));
        main.setDestination(destinationOf(cl));
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        main.setExecutor(executorService);
        main.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            List<String> argList = cl.getArgList();
            if (argList.isEmpty())
                main.retrieve();
            else
                for (String arg : argList)
                    main.retrieve(new File(arg));
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("movescu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("movescu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.movescu.MoveSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//from w w w  . jav  a2 s .  com
        CommandLine cl = parseComandLine(args);
        MoveSCU main = new MoveSCU();
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(main.conn, main.ae, cl);
        CLIUtils.configure(main.conn, cl);
        main.remote.setTlsProtocols(main.conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites());
        configureServiceClass(main, cl);
        configureKeys(main, cl);
        main.setPriority(CLIUtils.priorityOf(cl));
        main.setDestination(destinationOf(cl));
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        main.device.setExecutor(executorService);
        main.device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            List<String> argList = cl.getArgList();
            if (argList.isEmpty())
                main.retrieve();
            else
                for (String arg : argList)
                    main.retrieve(new File(arg));
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("movescu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("movescu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:com.opengamma.batch.BatchJobRunner.java

/**
 * Creates an runs a batch job based on a properties file and configuration.
 *///from  w w  w .  j  av a  2  s . com
public static void main(String[] args) throws Exception { // CSIGNORE
    if (args.length == 0) {
        usage();
        System.exit(-1);
    }

    CommandLine line = null;
    Properties configProperties = null;

    final String propertyFile = "batchJob.properties";

    String configPropertyFile = null;

    if (System.getProperty(propertyFile) != null) {
        configPropertyFile = System.getProperty(propertyFile);
        try {
            FileInputStream fis = new FileInputStream(configPropertyFile);
            configProperties = new Properties();
            configProperties.load(fis);
            fis.close();
        } catch (FileNotFoundException e) {
            s_logger.error("The system cannot find " + configPropertyFile);
            System.exit(-1);
        }
    } else {
        try {
            FileInputStream fis = new FileInputStream(propertyFile);
            configProperties = new Properties();
            configProperties.load(fis);
            fis.close();
            configPropertyFile = propertyFile;
        } catch (FileNotFoundException e) {
            // there is no config file so we expect command line arguments
            try {
                CommandLineParser parser = new PosixParser();
                line = parser.parse(getOptions(), args);
            } catch (ParseException e2) {
                usage();
                System.exit(-1);
            }
        }
    }

    RunCreationMode runCreationMode = getRunCreationMode(line, configProperties, configPropertyFile);
    if (runCreationMode == null) {
        // default
        runCreationMode = RunCreationMode.AUTO;
    }

    String engineURI = getProperty("engineURI", line, configProperties, configPropertyFile);

    String brokerURL = getProperty("brokerURL", line, configProperties, configPropertyFile);

    Instant valuationTime = getValuationTime(line, configProperties, configPropertyFile);
    LocalDate observationDate = getObservationDate(line, configProperties, configPropertyFile);

    UniqueId viewDefinitionUniqueId = getViewDefinitionUniqueId(line, configProperties);

    URI vpBase;
    try {
        vpBase = new URI(engineURI);
    } catch (URISyntaxException ex) {
        throw new OpenGammaRuntimeException("Invalid URI", ex);
    }

    ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(brokerURL);
    activeMQConnectionFactory.setWatchTopicAdvisories(false);

    JmsConnectorFactoryBean jmsConnectorFactoryBean = new JmsConnectorFactoryBean();
    jmsConnectorFactoryBean.setConnectionFactory(activeMQConnectionFactory);
    jmsConnectorFactoryBean.setName("Masters");

    JmsConnector jmsConnector = jmsConnectorFactoryBean.getObjectCreating();
    ScheduledExecutorService heartbeatScheduler = Executors.newSingleThreadScheduledExecutor();
    try {
        ViewProcessor vp = new RemoteViewProcessor(vpBase, jmsConnector, heartbeatScheduler);
        ViewClient vc = vp.createViewClient(UserPrincipal.getLocalUser());

        HistoricalMarketDataSpecification marketDataSpecification = MarketData.historical(observationDate,
                null);

        ViewExecutionOptions executionOptions = ExecutionOptions.batch(valuationTime, marketDataSpecification,
                null);

        vc.attachToViewProcess(viewDefinitionUniqueId, executionOptions);
        vc.waitForCompletion();
    } finally {
        heartbeatScheduler.shutdown();
    }
}

From source file:org.dcm4che.tool.getscu.GetSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from  w w w.java2 s.c o m*/
        CommandLine cl = parseComandLine(args);
        GetSCU main = new GetSCU();
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(main.conn, main.ae, cl);
        CLIUtils.configure(main.conn, cl);
        main.remote.setTlsProtocols(main.conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites());
        configureServiceClass(main, cl);
        configureKeys(main, cl);
        main.setPriority(CLIUtils.priorityOf(cl));
        configureStorageDirectory(main, cl);
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        main.device.setExecutor(executorService);
        main.device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            List<String> argList = cl.getArgList();
            if (argList.isEmpty())
                main.retrieve();
            else
                for (String arg : argList)
                    main.retrieve(new File(arg));
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("getscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("getscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.mppsscu.MppsSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from  w  w w . ja v a  2  s . c om*/
        CommandLine cl = parseComandLine(args);
        Device device = new Device("mppsscu");
        Connection conn = new Connection();
        device.addConnection(conn);
        ApplicationEntity ae = new ApplicationEntity("MPPSSCU");
        device.addApplicationEntity(ae);
        ae.addConnection(conn);
        final MppsSCU main = new MppsSCU(ae);
        configureMPPS(main, cl);
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(conn, main.ae, cl);
        CLIUtils.configure(conn, cl);
        main.remote.setTlsProtocols(conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(conn.getTlsCipherSuites());
        main.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        main.setAttributes(new Attributes());
        CLIUtils.addAttributes(main.attrs, cl.getOptionValues("s"));
        main.setUIDSuffix(cl.getOptionValue("uid-suffix"));
        List<String> argList = cl.getArgList();
        boolean echo = argList.isEmpty();
        if (!echo) {
            System.out.println(rb.getString("scanning"));
            DicomFiles.scan(argList, new DicomFiles.Callback() {

                @Override
                public boolean dicomFile(File f, Attributes fmi, long dsPos, Attributes ds) {
                    if (UID.ModalityPerformedProcedureStepSOPClass
                            .equals(fmi.getString(Tag.MediaStorageSOPClassUID))) {
                        return main.addMPPS(fmi.getString(Tag.MediaStorageSOPInstanceUID), ds);
                    }
                    return main.addInstance(ds);
                }
            });
        }
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        device.setExecutor(executorService);
        device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            if (echo)
                main.echo();
            else {
                main.createMpps();
                main.updateMpps();
            }
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("mppsscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("mppsscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.findscu.FindSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*  w w  w.j ava 2s .co  m*/
        CommandLine cl = parseComandLine(args);
        FindSCU main = new FindSCU();
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(main.conn, main.ae, cl);
        CLIUtils.configure(main.conn, cl);
        main.remote.setTlsProtocols(main.conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(main.conn.getTlsCipherSuites());
        configureServiceClass(main, cl);
        configureKeys(main, cl);
        configureOutput(main, cl);
        configureCancel(main, cl);
        main.setPriority(CLIUtils.priorityOf(cl));
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        main.device.setExecutor(executorService);
        main.device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            List<String> argList = cl.getArgList();
            if (argList.isEmpty())
                main.query();
            else
                for (String arg : argList)
                    main.query(new File(arg));
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("findscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("findscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che3.tool.mppsscu.MppsSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {/*from w  w w . j  a v  a  2s .c  o  m*/
        CommandLine cl = parseComandLine(args);
        Device device = new Device("mppsscu");
        Connection conn = new Connection();
        device.addConnection(conn);
        ApplicationEntity ae = new ApplicationEntity("MPPSSCU");
        device.addApplicationEntity(ae);
        ae.addConnection(conn);
        final MppsSCU main = new MppsSCU(ae);
        configureMPPS(main, cl);
        CLIUtils.configureConnect(main.remote, main.rq, cl);
        CLIUtils.configureBind(conn, main.ae, cl);
        CLIUtils.configure(conn, cl);
        main.remote.setTlsProtocols(conn.getTlsProtocols());
        main.remote.setTlsCipherSuites(conn.getTlsCipherSuites());
        main.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        main.setAttributes(new Attributes());
        CLIUtils.addAttributes(main.attrs, cl.getOptionValues("s"));
        main.setUIDSuffix(cl.getOptionValue("uid-suffix"));
        List<String> argList = cl.getArgList();
        boolean echo = argList.isEmpty();
        if (!echo) {
            System.out.println(rb.getString("scanning"));
            main.scanFiles(argList, true);
        }
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        device.setExecutor(executorService);
        device.setScheduledExecutor(scheduledExecutorService);
        try {
            main.open();
            if (echo)
                main.echo();
            else {
                main.createMpps();
                main.updateMpps();
            }
        } finally {
            main.close();
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("mppsscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("mppsscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}

From source file:org.dcm4che.tool.stgcmtscu.StgCmtSCU.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    try {//from   w  w w . j  a  v a2s.c om
        CommandLine cl = parseComandLine(args);
        Device device = new Device("stgcmtscu");
        Connection conn = new Connection();
        device.addConnection(conn);
        ApplicationEntity ae = new ApplicationEntity("STGCMTSCU");
        device.addApplicationEntity(ae);
        ae.addConnection(conn);
        final StgCmtSCU stgcmtscu = new StgCmtSCU(ae);
        CLIUtils.configureConnect(stgcmtscu.remote, stgcmtscu.rq, cl);
        CLIUtils.configureBind(conn, stgcmtscu.ae, cl);
        CLIUtils.configure(conn, cl);
        stgcmtscu.remote.setTlsProtocols(conn.getTlsProtocols());
        stgcmtscu.remote.setTlsCipherSuites(conn.getTlsCipherSuites());
        stgcmtscu.setTransferSyntaxes(CLIUtils.transferSyntaxesOf(cl));
        stgcmtscu.setStatus(CLIUtils.getIntOption(cl, "status", 0));
        stgcmtscu.setSplitTag(getSplitTag(cl));
        stgcmtscu.setKeepAlive(cl.hasOption("keep-alive"));
        stgcmtscu.setStorageDirectory(getStorageDirectory(cl));
        stgcmtscu.setAttributes(new Attributes());
        CLIUtils.addAttributes(stgcmtscu.attrs, cl.getOptionValues("s"));
        stgcmtscu.setUIDSuffix(cl.getOptionValue("uid-suffix"));
        List<String> argList = cl.getArgList();
        boolean echo = argList.isEmpty();
        if (!echo) {
            LOG.info(rb.getString("scanning"));
            DicomFiles.scan(argList, new DicomFiles.Callback() {

                @Override
                public boolean dicomFile(File f, Attributes fmi, long dsPos, Attributes ds) {
                    return stgcmtscu.addInstance(ds);
                }
            });
        }
        ExecutorService executorService = Executors.newCachedThreadPool();
        ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
        device.setExecutor(executorService);
        device.setScheduledExecutor(scheduledExecutorService);
        device.bindConnections();
        try {
            stgcmtscu.open();
            if (echo)
                stgcmtscu.echo();
            else
                stgcmtscu.sendRequests();
        } finally {
            stgcmtscu.close();
            if (conn.isListening()) {
                device.waitForNoOpenConnections();
                device.unbindConnections();
            }
            executorService.shutdown();
            scheduledExecutorService.shutdown();
        }
    } catch (ParseException e) {
        System.err.println("stgcmtscu: " + e.getMessage());
        System.err.println(rb.getString("try"));
        System.exit(2);
    } catch (Exception e) {
        System.err.println("stgcmtscu: " + e.getMessage());
        e.printStackTrace();
        System.exit(2);
    }
}