Example usage for java.util.concurrent ExecutorService execute

List of usage examples for java.util.concurrent ExecutorService execute

Introduction

In this page you can find the example usage for java.util.concurrent ExecutorService execute.

Prototype

void execute(Runnable command);

Source Link

Document

Executes the given command at some time in the future.

Usage

From source file:com.testmax.framework.BasePage.java

private ExecutorService setUnitPerformanceExecutor(BasePage page) {
    //get action string by removing "unit@" prefix
    String action = this.action.substring(this.action.indexOf("@") + 1);

    this.newThreadCount = this.threadCount;
    ExecutorService exec = Executors.newFixedThreadPool(this.getThreadCount());
    for (int count = 0; count < this.getThreadCount(); count++) {
        this.urlConfig = this.pageUrl.getUrlConfig(action);
        exec.execute(new HttpThread(page, action));
        if (count == 0) {
            executeGraph.createChart(this.timeout);
            responseGraph.createChart(this.timeout);
            elaspedTimeGraph.createChart(this.timeout);
            activeThreadGraph.createChart(this.timeout);
        }/*from  w ww .j a  v a 2s .c  o  m*/
    }
    exec.shutdown();
    return (exec);
}

From source file:org.alfresco.repo.batch.BatchProcessor.java

/**
 * Invokes the worker for each entry in the collection, managing transactions and collating success / failure
 * information./*ww w  .ja  v a 2  s.  c o  m*/
 * 
 * @param worker
 *            the worker
 * @param splitTxns
 *            Can the modifications to Alfresco be split across multiple transactions for maximum performance? If
 *            <code>true</code>, worker invocations are isolated in separate transactions in batches for
 *            increased performance. If <code>false</code>, all invocations are performed in the current
 *            transaction. This is required if calling synchronously (e.g. in response to an authentication event in
 *            the same transaction).
 * @return the number of invocations
 */
@SuppressWarnings("serial")
public int process(final BatchProcessWorker<T> worker, final boolean splitTxns) {
    int count = workProvider.getTotalEstimatedWorkSize();
    synchronized (this) {
        this.startTime = new Date();
        if (this.logger.isInfoEnabled()) {
            if (count >= 0) {
                this.logger.info(getProcessName() + ": Commencing batch of " + count + " entries");
            } else {
                this.logger.info(getProcessName() + ": Commencing batch");

            }
        }
    }

    // Create a thread pool executor with the specified number of threads and a finite blocking queue of jobs
    ExecutorService executorService = splitTxns && this.workerThreads > 1
            ? new ThreadPoolExecutor(this.workerThreads, this.workerThreads, 0L, TimeUnit.MILLISECONDS,
                    new ArrayBlockingQueue<Runnable>(this.workerThreads * this.batchSize * 10) {
                        // Add blocking behaviour to work queue
                        @Override
                        public boolean offer(Runnable o) {
                            try {
                                put(o);
                            } catch (InterruptedException e) {
                                return false;
                            }
                            return true;
                        }

                    }, threadFactory)
            : null;
    try {
        Iterator<T> iterator = new WorkProviderIterator<T>(this.workProvider);
        int id = 0;
        List<T> batch = new ArrayList<T>(this.batchSize);
        while (iterator.hasNext()) {
            batch.add(iterator.next());
            boolean hasNext = iterator.hasNext();
            if (batch.size() >= this.batchSize || !hasNext) {
                final TxnCallback callback = new TxnCallback(id++, worker, batch, splitTxns);
                if (hasNext) {
                    batch = new ArrayList<T>(this.batchSize);
                }

                if (executorService == null) {
                    callback.run();
                } else {
                    executorService.execute(callback);
                }
            }
        }
        return count;
    } finally {
        if (executorService != null) {
            executorService.shutdown();
            try {
                executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
            } catch (InterruptedException e) {
            }
        }
        synchronized (this) {
            reportProgress(true);
            this.endTime = new Date();
            if (this.logger.isInfoEnabled()) {
                if (count >= 0) {
                    this.logger.info(getProcessName() + ": Completed batch of " + count + " entries");
                } else {
                    this.logger.info(getProcessName() + ": Completed batch");

                }
            }
            if (this.totalErrors > 0 && this.logger.isErrorEnabled()) {
                this.logger.error(
                        getProcessName() + ": " + this.totalErrors
                                + " error(s) detected. Last error from entry \"" + this.lastErrorEntryId + "\"",
                        this.lastError);
            }
        }
    }
}

From source file:com.smartmarmot.orabbix.Orabbixmon.java

@Override
public void run() {
    try {/*ww  w.j a v a2s  . co m*/
        Configurator cfg = null;
        try {
            cfg = new Configurator(configFile);
        } catch (Exception e) {
            SmartLogger.logThis(Level.ERROR, "Error while creating configurator with " + configFile + " " + e);
        }
        RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
        String pid = rmxb.getName();
        SmartLogger.logThis(Level.INFO,
                Constants.PROJECT_NAME + " started with pid:" + pid.split("@")[0].toString());
        // System.out.print("pid: "+pid.split("@")[0].toString());
        String pidfile = cfg.getPidFile();
        try {
            Utility.writePid(pid.split("@")[0].toString(), pidfile);
        } catch (Exception e) {
            SmartLogger.logThis(Level.ERROR, "Error while trying to write pidfile " + e);
        }

        Locale.setDefault(Locale.US);

        DBConn[] myDBConn = cfg.getConnections();

        if (myDBConn == null) {
            SmartLogger.logThis(Level.ERROR, "ERROR on main - Connections is null");
            throw new Exception("ERROR on main - Connections is null");

        } else if (myDBConn.length == 0) {
            SmartLogger.logThis(Level.ERROR, "ERROR on main - Connections is empty");
            throw new Exception("ERROR on main - Connections is empty");
        }

        /**
         * retrieve maxThread
         */
        Integer maxThread = 0;
        try {
            maxThread = cfg.getMaxThread();
        } catch (Exception e) {
            SmartLogger.logThis(Level.WARN,
                    "MaxThread not defined calculated maxThread = " + myDBConn.length * 3);
        }
        if (maxThread == null)
            maxThread = 0;
        if (maxThread == 0) {
            maxThread = myDBConn.length * 3;
        }

        ExecutorService executor = Executors.newFixedThreadPool(maxThread.intValue());
        /**
         * populate qbox
         */
        Hashtable<String, Querybox> qbox = new Hashtable<String, Querybox>();
        for (int i = 0; i < myDBConn.length; i++) {
            Querybox qboxtmp = Configurator.buildQueryBoxbyDBName(myDBConn[i].getName());
            qbox.put(myDBConn[i].getName(), qboxtmp);
        } // for (int i = 0; i < myDBConn.length; i++) {

        cfg = null;
        /**
         * daemon begin here
         */
        while (running) {
            /**
             * istantiate a new configurator
             */
            Configurator c = new Configurator(configFile);

            /*
             * here i rebuild DB's List
             */
            if (!c.isEqualsDBList(myDBConn)) {

                // rebuild connections DBConn[]

                myDBConn = c.rebuildDBList(myDBConn);
                for (int i = 1; i < myDBConn.length; i++) {
                    if (!qbox.containsKey(myDBConn[i].getName())) {
                        Querybox qboxtmp = Configurator.buildQueryBoxbyDBName(myDBConn[i].getName());
                        qbox.put(myDBConn[i].getName(), qboxtmp);
                    }
                }
            } // if (!c.isEqualsDBList(myDBConn)) {

            /*
             * ready to run query
             */

            for (int i = 0; i < myDBConn.length; i++) {
                Querybox actqb = qbox.get(myDBConn[i].getName());
                actqb.refresh();
                Query[] q = actqb.getQueries();

                SharedPoolDataSource spds = myDBConn[i].getSPDS();

                Hashtable<String, Integer> zabbixServers = c.getZabbixServers();
                SmartLogger.logThis(Level.DEBUG, "Ready to run DBJob for dbname ->" + myDBConn[i].getName());
                Runnable runner = new DBJob(spds, q, Constants.QUERY_LIST, zabbixServers,
                        myDBConn[i].getName());
                executor.execute(runner);

            } // for (int i = 0; i < myDBConn.length; i++) {
            Thread.sleep(60 * 1000);
            SmartLogger.logThis(Level.DEBUG, "Waking up Goood Morning");
        }
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        System.out.println("Stopping");
        e1.printStackTrace();
        stopped = true;
    }

}

From source file:ubic.gemma.core.loader.expression.geo.GeoFamilyParser.java

@Override
public void parse(InputStream is) throws IOException {
    if (is == null) {
        throw new IOException("Inputstream was null");
    }//from w  w  w  .  ja v a2 s.  c  o m

    if (is.available() == 0) {
        throw new IOException("No bytes to read from the input stream.");
    }

    try (final BufferedReader dis = new BufferedReader(new InputStreamReader(is))) {

        GeoFamilyParser.log.debug("Parsing....");

        final ExecutorService executor = Executors.newSingleThreadExecutor();

        FutureTask<Exception> future = new FutureTask<>(new Callable<Exception>() {
            @Override
            public Exception call() {
                try {
                    GeoFamilyParser.this.doParse(dis);
                    dis.close();
                    return null;
                } catch (Exception e) {
                    GeoFamilyParser.log.error(e, e);
                    return e;
                }
            }
        });

        executor.execute(future);
        executor.shutdown();

        while (!future.isDone() && !future.isCancelled()) {
            try {
                TimeUnit.SECONDS.sleep(5L);
            } catch (InterruptedException e) {
                // probably cancelled.
                dis.close();
                return;
            }
            GeoFamilyParser.log.info(parsedLines + " lines parsed.");
        }

        try {
            Exception e = future.get();
            if (e != null) {
                GeoFamilyParser.log.error(e.getMessage());
                throw new RuntimeException(e.getCause());
            }
        } catch (ExecutionException e) {
            throw new RuntimeException("Parse failed", e.getCause());
        } catch (java.util.concurrent.CancellationException e) {
            throw new RuntimeException("Parse was cancelled", e.getCause());
        } catch (InterruptedException e) {
            throw new RuntimeException("Parse was interrupted", e.getCause());
        }

        executor.shutdownNow();

        assert future.isDone();
        // assert executor.isTerminated();

        GeoFamilyParser.log.info("Done parsing.");
    }
}

From source file:ubic.gemma.loader.expression.geo.GeoFamilyParser.java

@Override
public void parse(InputStream is) throws IOException {
    if (is == null) {
        throw new IOException("Inputstream was null");
    }//from   ww w.  ja v  a 2 s.  c  om

    if (is.available() == 0) {
        throw new IOException("No bytes to read from the input stream.");
    }

    final BufferedReader dis = new BufferedReader(new InputStreamReader(is));

    log.debug("Parsing....");

    final ExecutorService executor = Executors.newSingleThreadExecutor();

    FutureTask<Exception> future = new FutureTask<Exception>(new Callable<Exception>() {
        @Override
        public Exception call() {
            try {
                return doParse(dis);
            } catch (Exception e) {
                log.error(e, e);
                return e;
            }

        }
    });

    executor.execute(future);
    executor.shutdown();

    while (!future.isDone() && !future.isCancelled()) {
        try {
            TimeUnit.SECONDS.sleep(5L);
        } catch (InterruptedException e) {
            // probably cancelled.
            return;
        }
        log.info(parsedLines + " lines parsed.");
    }

    try {
        Exception e = future.get();
        if (e != null) {
            log.error(e.getMessage());
            throw new RuntimeException(e.getCause());
        }
    } catch (ExecutionException e) {
        throw new RuntimeException("Parse failed", e.getCause());
    } catch (java.util.concurrent.CancellationException e) {
        throw new RuntimeException("Parse was cancelled", e.getCause());
    } catch (InterruptedException e) {
        throw new RuntimeException("Parse was interrupted", e.getCause());
    }

    executor.shutdownNow();

    assert future.isDone();
    // assert executor.isTerminated();

    log.info("Done parsing.");
}

From source file:org.corpus_tools.peppermodules.annis.Salt2ANNISMapper.java

@Override
public DOCUMENT_STATUS mapSDocument() {

    this.preorderTable = new ConcurrentHashMap<>();
    this.postorderTable = new ConcurrentHashMap<>();
    prePostOrder = 0l;//from  w w w.ja v  a 2 s.c  o m

    numberOfMappedNodes.set(0);

    if (this.getDocument() == null || this.getDocument().getDocumentGraph() == null) {
        throw new PepperModuleException(this, "Cannot map sDocumentGraph, because sDocumentGraph is null.");
    }

    {//start traversion of documentStructure

        try {

            if (this.getDocument().getDocumentGraph().getNodes() != null) {
                this.numberOfDocumentNodes = this.getDocument().getDocumentGraph().getNodes().size();
            }

            /**
             * traverse by SpanningRelations: DOCUMENT_STRUCTURE_CR
             * DominanceRelations: DOCUMENT_STRUCTURE_DR PointingRelations:
             * DOCUMENT_STRUCTURE_PR
             *
             * DominanceRelations Subcomponents: DOCUMENT_STRUCTURE_DR_SUB
             * PointingRelations Subcomponents: DOCUMENT_STRUCTURE_PR_SUB
             *
             * Dominance relations may consist of different subcomponents since
             * there are "edge" and "secedge" types
             *
             * Since every root node has it's own component, the pre and post order
             * needs to be 0 for the root node. You need to handle this.
             */
            List<? extends SNode> sRelationRoots;
            Multimap<String, SNode> subComponentRoots;
            //        Map<String, List<SNode>> subComponentRoots;

            Map<SToken, Long> token2Index = calculateToken2Index(getDocument().getDocumentGraph());

            // START Step 1: map SOrderRelation
            subComponentRoots = this.getDocument().getDocumentGraph()
                    .getRootsByRelationType(SALT_TYPE.SORDER_RELATION);
            if (subComponentRoots != null) {
                if (subComponentRoots.size() > 0) {
                    for (Entry<String, SNode> entry : subComponentRoots.entries()) {
                        SRelation2ANNISMapper sOrderRelationMapper = new SOrderRelation2ANNISMapper(
                                getIdManager(), getDocument().getDocumentGraph(), token2Index, tw_node,
                                tw_nodeAnno, tw_rank, tw_edgeAnno, tw_component, this);

                        String traversionType = entry.getKey();
                        if (SaltUtil.SALT_NULL_VALUE.equals(traversionType)) {
                            traversionType = "default_seg";
                        }
                        sOrderRelationMapper.setTraversionSType(traversionType);
                        sOrderRelationMapper.mapSRelations2ANNIS(subComponentRoots.get(entry.getKey()),
                                SALT_TYPE.SORDER_RELATION, null);

                    }
                }
            }
            // END Step 1: map SOrderRelation

            // also map the timeline (by creating a virtual tokenization if necessary)
            STimelineRelation2ANNISMapper timelineMapper = new STimelineRelation2ANNISMapper(getIdManager(),
                    getDocument().getDocumentGraph(), token2Index, tw_node, tw_nodeAnno, tw_rank, tw_edgeAnno,
                    tw_component, this, mergeTextsWithTimeline);
            timelineMapper.run();

            // START Step 2: map SText
            if (idManager.hasVirtualTokenization()) {
                Long sDocID;
                Long textId = 0l;
                String sDocumentElementId = this.getDocument().getId();

                if (sDocumentElementId == null) {
                    throw new PepperModuleException(this,
                            "SId Id of the document '" + this.getDocument().getName() + "' is NULL!");
                }
                sDocID = this.idManager.getNewCorpusTabId(sDocumentElementId);
                String textName = "sText0";
                String textContent = Strings.repeat(" ", idManager.getNumberOfVirtualToken());
                ArrayList<String> tuple = new ArrayList<>();
                tuple.add(sDocID.toString());
                tuple.add(textId.toString());
                tuple.add(textName);
                tuple.add(textContent);

                long transactionId = tw_text.beginTA();
                try {
                    tw_text.addTuple(transactionId, tuple);
                    tw_text.commitTA(transactionId);

                } catch (FileNotFoundException e) {
                    tw_text.abortTA(transactionId);
                    throw new PepperModuleException(this,
                            "Could not write to the node.tab, exception was" + e.getMessage());
                }
            } else {
                this.mapSText();
            }

            ExecutorService exec = null;
            if (mapRelationsInParallel) {
                exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
            }

            subComponentRoots = getDocument().getDocumentGraph()
                    .getRootsByRelationType(SALT_TYPE.SPOINTING_RELATION);
            if (subComponentRoots != null) {
                //System.out.println("The Pointing relation graphs have "+ subComponentRoots.size() + " STypes.");
                if (subComponentRoots.size() > 0) {

                    for (String key : subComponentRoots.keySet()) {
                        //System.out.println("Count of PR roots for key "+key+" : "+subComponentRoots.get(key).size());
                        //System.out.println("Mapping PointingRelation subcomponents with sType: "+key);
                        SRelation2ANNISMapper sPointingSubRelationMapper = new SPointingRelation2ANNISMapper(
                                getIdManager(), getDocument().getDocumentGraph(), token2Index, tw_node,
                                tw_nodeAnno, tw_rank, tw_edgeAnno, tw_component, this);
                        sPointingSubRelationMapper.mapSRelations2ANNIS(subComponentRoots.get(key),
                                SALT_TYPE.SPOINTING_RELATION, TRAVERSION_TYPE.DOCUMENT_STRUCTURE_PR);
                        sPointingSubRelationMapper.setTraversionSType(key);
                        if (exec != null) {
                            exec.execute(sPointingSubRelationMapper);
                        } else {
                            sPointingSubRelationMapper.run();
                        }
                    }
                } else {
                    //System.out.println("No PointingRelation components found (null map)");
                }
            } else {
                //System.out.println("No PointingRelation components found (empty map)");
            }
            // END Step 2: map SPointingRelations

            // START Step 3: map SDominanceRelations
            sRelationRoots = this.getDocument().getDocumentGraph()
                    .getRootsByRelation(SALT_TYPE.SDOMINANCE_RELATION);
            if (sRelationRoots != null) {
                if (sRelationRoots.size() > 0) {
                    SRelation2ANNISMapper sDominanceRelationMapper = new SDominanceRelation2ANNISMapper(
                            getIdManager(), getDocument().getDocumentGraph(), token2Index, tw_node, tw_nodeAnno,
                            tw_rank, tw_edgeAnno, tw_component, this);
                    sDominanceRelationMapper.mapSRelations2ANNIS(sRelationRoots, SALT_TYPE.SDOMINANCE_RELATION,
                            TRAVERSION_TYPE.DOCUMENT_STRUCTURE_DR);
                    if (exec != null) {
                        exec.execute(sDominanceRelationMapper);
                    } else {
                        sDominanceRelationMapper.run();
                    }
                }
            }
            // END Step 3: map SDominanceRelations

            // START Step 3.1 : map the subComponents of the SDominanceRelations
            subComponentRoots = getDocument().getDocumentGraph()
                    .getRootsByRelationType(SALT_TYPE.SDOMINANCE_RELATION);
            if (subComponentRoots != null) {
                //System.out.println("The Dominance relation graphs have "+ subComponentRoots.size() + " STypes.");
                if (subComponentRoots.size() > 0) {

                    Set<String> domComponentTypeNames = subComponentRoots.keySet();

                    // only output the named relation types if there the user has not choosen
                    // to include them or if there are more than 1 named types
                    if (!((ANNISExporterProperties) this.getProperties()).getExcludeSingleDomType()
                            || domComponentTypeNames.size() >= 2) {
                        for (String key : domComponentTypeNames) {

                            if (!SaltUtil.SALT_NULL_VALUE.equals(key)) {

                                SRelation2ANNISMapper sDominanceSubRelationMapper = new SDominanceRelation2ANNISMapper(
                                        getIdManager(), getDocument().getDocumentGraph(), token2Index, tw_node,
                                        tw_nodeAnno, tw_rank, tw_edgeAnno, tw_component, this);
                                sDominanceSubRelationMapper.setTraversionSType(key);
                                sDominanceSubRelationMapper.mapSRelations2ANNIS(subComponentRoots.get(key),
                                        SALT_TYPE.SDOMINANCE_RELATION, TRAVERSION_TYPE.DOCUMENT_STRUCTURE_DR);
                                if (exec != null) {
                                    exec.execute(sDominanceSubRelationMapper);
                                } else {
                                    sDominanceSubRelationMapper.run();
                                }
                            }
                        }
                    }
                } else {
                    //System.out.println("No DominanceRelation subcomponents found (null map)");
                }
            } else {
                //System.out.println("No DominanceRelation subcomponents found (empty map)");
            }
            // END Step 3.1 : map the subComponents of the SDominanceRelations

            // START Step 4: map SSpanningrelations
            sRelationRoots = this.getDocument().getDocumentGraph()
                    .getRootsByRelation(SALT_TYPE.SSPANNING_RELATION);
            if (sRelationRoots != null) {
                if (sRelationRoots.size() > 0) {
                    SRelation2ANNISMapper spanningRelationMapper = new SSpanningRelation2ANNISMapper(
                            getIdManager(), getDocument().getDocumentGraph(), token2Index, tw_node, tw_nodeAnno,
                            tw_rank, tw_edgeAnno, tw_component, this);
                    spanningRelationMapper.mapSRelations2ANNIS(sRelationRoots, SALT_TYPE.SSPANNING_RELATION,
                            TRAVERSION_TYPE.DOCUMENT_STRUCTURE_CR);
                    if (exec != null) {
                        exec.execute(spanningRelationMapper);
                    } else {
                        spanningRelationMapper.run();
                    }
                }
            }
            // END Step 4: map SSpanningrelations

            // START Step 5: map SMedialRelations
            sRelationRoots = this.getDocument().getDocumentGraph().getTokens();
            if (sRelationRoots != null) {
                if (sRelationRoots.size() > 0) {
                    SRelation2ANNISMapper audioRelationMapper = new Audio2ANNISMapper(getIdManager(),
                            getDocument().getDocumentGraph(), token2Index, tw_node, tw_nodeAnno, tw_rank,
                            tw_edgeAnno, tw_component, this);
                    audioRelationMapper.mapSRelations2ANNIS(sRelationRoots,
                            SALT_TYPE.STIME_OVERLAPPING_RELATION, TRAVERSION_TYPE.DOCUMENT_STRUCTURE_AUDIO);
                    if (exec != null) {
                        exec.execute(audioRelationMapper);
                    } else {
                        audioRelationMapper.run();
                    }
                }
            }
            // END Step 5: map SMedialRelations

            if (exec != null) {
                exec.shutdown();
                while (!exec.awaitTermination(60, TimeUnit.SECONDS)) {
                    // wait to finish
                }
            }

            // START Step 6: map all SToken which were not mapped, yet
            SRelation2ANNISMapper mapper = new SSpanningRelation2ANNISMapper(getIdManager(),
                    getDocument().getDocumentGraph(), token2Index, tw_node, tw_nodeAnno, tw_rank, tw_edgeAnno,
                    tw_component, this);
            mapper.beginTransaction();
            for (SNode node : getDocument().getDocumentGraph().getTokens()) {
                if (this.idManager.getVirtualisedSpanId(node.getId()) == null) {
                    mapper.mapSNode(node);
                }
            }
            mapper.commitTransaction();
            // END Step 6: map all SToken which were not mapped, yet

        } catch (PepperModuleException e) {
            throw new PepperModuleException(this,
                    "Some error occurs while traversing document structure graph.", e);
        } catch (InterruptedException e) {
            throw new PepperModuleException(this,
                    "Some error occurs while traversing document structure graph.", e);
        }
    } //start traversion of corpus structure

    mergeLocalStatsIntoGlobal();

    setProgress(1.0);
    return DOCUMENT_STATUS.COMPLETED;
}

From source file:br.prof.salesfilho.oci.service.BodyWomanNudeClassifier.java

public void tClassify() {

    long startTime;
    long endTime;
    double totalTime = 0;

    EuclidianClassifier chestWorker;//from   w ww  .j av  a2s. co m
    EuclidianClassifier buttockWorker;
    EuclidianClassifier genitalWorker;

    ClassificationResult classificationResult;
    ExecutorService executor;

    bodyWomanDescriptorService.openDatabase(new File(this.databaseName));

    BodyPartDescriptor nudeChestDescriptor = bodyWomanDescriptorService
            .findNudeBodyPartDescriptorByName("Chest");
    BodyPartDescriptor notNudeChestDescriptor = bodyWomanDescriptorService
            .findNotNudeBodyPartDescriptorByName("Chest");

    BodyPartDescriptor nudeButtockDescriptor = bodyWomanDescriptorService
            .findNudeBodyPartDescriptorByName("Buttock");
    BodyPartDescriptor notNudeButtockDescriptor = bodyWomanDescriptorService
            .findNotNudeBodyPartDescriptorByName("Buttock");

    BodyPartDescriptor nudeGenitalDescriptor = bodyWomanDescriptorService
            .findNudeBodyPartDescriptorByName("Genital");
    BodyPartDescriptor notNudeGenitalDescriptor = bodyWomanDescriptorService
            .findNotNudeBodyPartDescriptorByName("Genital");

    fileList = OCIUtils.getImageFiles(this.inputDir);

    List<EuclidianClassifier> classifiers = new ArrayList();

    for (String imagePath : fileList) {
        startTime = System.currentTimeMillis();

        try {
            System.out.println(
                    "-------------------------------------------------------------------------------------");
            System.out.println("Classifying image...: ".concat(imagePath));
            System.out.println(
                    "-------------------------------------------------------------------------------------");

            BufferedImage img = ImageIO.read(new File(imagePath));
            ImageProcessor imageProcessor = new ImageProcessor(img);
            imageProcessorService = new ImageProcessorService(imageProcessor);
            List<BufferedImage> partImageList = imageProcessorService.getSubImages(128);

            //Create new thread pool to each image file
            executor = Executors.newFixedThreadPool(10);
            for (BufferedImage subImg : partImageList) {

                chestWorker = new EuclidianClassifier(nudeChestDescriptor, notNudeChestDescriptor, subImg,
                        this.kernelSize);
                chestWorker.setClassificationLevel(this.classificationLevel);
                executor.execute(chestWorker);
                classifiers.add(chestWorker);

                buttockWorker = new EuclidianClassifier(nudeButtockDescriptor, notNudeButtockDescriptor, subImg,
                        this.kernelSize);
                buttockWorker.setClassificationLevel(this.classificationLevel);
                executor.execute(buttockWorker);
                classifiers.add(buttockWorker);

                genitalWorker = new EuclidianClassifier(nudeGenitalDescriptor, notNudeGenitalDescriptor, subImg,
                        this.kernelSize);
                genitalWorker.setClassificationLevel(this.classificationLevel);
                executor.execute(genitalWorker);
                classifiers.add(genitalWorker);
            }
            //Wait finish
            executor.shutdown();
            while (!executor.isTerminated()) {
            }

            classificationResult = printResult(classifiers);
            classificationResult.setFileName(imagePath);

            endTime = System.currentTimeMillis();

            classificationResult.setExecutionTime(endTime - startTime);
            classificationResults.add(classificationResult);

            classifiers.clear();

        } catch (IOException ex) {
            Logger.getLogger(BodyWomanNudeClassifier.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
    System.out.println("--------------------------------------------------------");
    System.out.println("Total time.: " + (totalTime) + " ms.");
    System.out.println("--------------------------------------------------------");
}

From source file:org.apache.solr.cloud.ZkController.java

/**
 * When a leader receives a communication error when trying to send a request to a replica,
 * it calls this method to ensure the replica enters recovery when connectivity is restored.
 * <p>/*from www . j a  va  2  s. c o  m*/
 * returns true if the node hosting the replica is still considered "live" by ZooKeeper;
 * false means the node is not live either, so no point in trying to send recovery commands
 * to it.
 */
public boolean ensureReplicaInLeaderInitiatedRecovery(final CoreContainer container, final String collection,
        final String shardId, final ZkCoreNodeProps replicaCoreProps, CoreDescriptor leaderCd,
        boolean forcePublishState) throws KeeperException, InterruptedException {
    final String replicaUrl = replicaCoreProps.getCoreUrl();

    if (collection == null)
        throw new IllegalArgumentException(
                "collection parameter cannot be null for starting leader-initiated recovery for replica: "
                        + replicaUrl);

    if (shardId == null)
        throw new IllegalArgumentException(
                "shard parameter cannot be null for starting leader-initiated recovery for replica: "
                        + replicaUrl);

    if (replicaUrl == null)
        throw new IllegalArgumentException(
                "replicaUrl parameter cannot be null for starting leader-initiated recovery");

    // First, determine if this replica is already in recovery handling
    // which is needed because there can be many concurrent errors flooding in
    // about the same replica having trouble and we only need to send the "needs"
    // recovery signal once
    boolean nodeIsLive = true;
    String replicaNodeName = replicaCoreProps.getNodeName();
    String replicaCoreNodeName = ((Replica) replicaCoreProps.getNodeProps()).getName();
    assert replicaCoreNodeName != null : "No core name for replica " + replicaNodeName;
    synchronized (replicasInLeaderInitiatedRecovery) {
        if (replicasInLeaderInitiatedRecovery.containsKey(replicaUrl)) {
            if (!forcePublishState) {
                log.debug("Replica {} already in leader-initiated recovery handling.", replicaUrl);
                return false; // already in this recovery process
            }
        }

        // we only really need to try to start the LIR process if the node itself is "live"
        if (getZkStateReader().getClusterState().liveNodesContain(replicaNodeName)) {

            LeaderInitiatedRecoveryThread lirThread = new LeaderInitiatedRecoveryThread(this, container,
                    collection, shardId, replicaCoreProps, 120, leaderCd);
            ExecutorService executor = container.getUpdateShardHandler().getUpdateExecutor();
            try {
                MDC.put("DistributedUpdateProcessor.replicaUrlToRecover", replicaCoreProps.getCoreUrl());
                executor.execute(lirThread);
            } finally {
                MDC.remove("DistributedUpdateProcessor.replicaUrlToRecover");
            }

            // create a znode that requires the replica needs to "ack" to verify it knows it was out-of-sync
            replicasInLeaderInitiatedRecovery.put(replicaUrl,
                    getLeaderInitiatedRecoveryZnodePath(collection, shardId, replicaCoreNodeName));
            log.info(
                    "Put replica core={} coreNodeName={} on " + replicaNodeName
                            + " into leader-initiated recovery.",
                    replicaCoreProps.getCoreName(), replicaCoreNodeName);
        } else {
            nodeIsLive = false; // we really don't need to send the recovery request if the node is NOT live
            log.info("Node " + replicaNodeName
                    + " is not live, so skipping leader-initiated recovery for replica: core={} coreNodeName={}",
                    replicaCoreProps.getCoreName(), replicaCoreNodeName);
            // publishDownState will be false to avoid publishing the "down" state too many times
            // as many errors can occur together and will each call into this method (SOLR-6189)        
        }
    }

    return nodeIsLive;
}

From source file:org.pentaho.support.standalone.SDSupportUtility.java

/**
 * initializing UI//from w  w  w .j  a  v  a 2  s.  com
 * 
 * @throws Exception
 */
public SDSupportUtility() throws Exception {

    prop = loadProperty();

    setResizable(false);
    setTitle(SDConstant.PENT_SUP_WIZARD);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 665, 516);

    contentPane = new JPanel();
    contentPane.setBackground(UIManager.getColor("Button.background"));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel lblLastAttached = new JLabel("Last Attached");
    lblLastAttached.setOpaque(false);
    lblLastAttached.setHorizontalAlignment(SwingConstants.LEFT);
    lblLastAttached.setBounds(322, 335, 127, 23);
    contentPane.add(lblLastAttached);

    JLabel lblPentahoCustomerSupport = new JLabel("Pentaho Customer Support Wizard");
    lblPentahoCustomerSupport.setForeground(new Color(51, 51, 51));
    lblPentahoCustomerSupport.setVerticalAlignment(SwingConstants.TOP);
    lblPentahoCustomerSupport.setHorizontalAlignment(SwingConstants.RIGHT);
    lblPentahoCustomerSupport.setFont(new Font("Tahoma", Font.BOLD, 23));
    lblPentahoCustomerSupport.setBounds(130, 109, 506, 37);
    contentPane.add(lblPentahoCustomerSupport);

    JLabel lbllogo = new JLabel();
    lbllogo.setIcon(new ImageIcon(
            SDSupportUtility.class.getResource("/org/pentaho/support/standalone/puc-login-logo.png")));
    lbllogo.setBounds(10, 11, 409, 93);
    contentPane.add(lbllogo);

    chckbxNewCheckBoxEnvironment = new JCheckBox("Environment");
    chckbxNewCheckBoxEnvironment.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.ENVIRONMENT);
            } else {
                ArgList.remove(SDConstant.ENVIRONMENT);
            }
        }
    });
    chckbxNewCheckBoxEnvironment.setBounds(109, 268, 243, 23);
    contentPane.add(chckbxNewCheckBoxEnvironment);
    chckbxNewCheckBoxEnvironment.setOpaque(false);

    chckbxNewCheckBoxStructure = new JCheckBox("Structure Details");
    chckbxNewCheckBoxStructure.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.STRUCT);
            } else {
                ArgList.remove(SDConstant.STRUCT);
            }
        }
    });
    chckbxNewCheckBoxStructure.setBounds(377, 190, 248, 23);
    contentPane.add(chckbxNewCheckBoxStructure);
    chckbxNewCheckBoxStructure.setOpaque(false);

    chckbxLogs = new JCheckBox("Logs");
    chckbxLogs.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.LOGS);
            } else {
                ArgList.remove(SDConstant.LOGS);
            }
        }
    });
    chckbxLogs.setBounds(377, 164, 248, 23);
    contentPane.add(chckbxLogs);
    chckbxLogs.setOpaque(false);

    chckbxGetSecureFiles = new JCheckBox("Secure Files");
    chckbxGetSecureFiles.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.SECURITY);
            } else {
                ArgList.remove(SDConstant.SECURITY);
            }
        }
    });
    chckbxGetSecureFiles.setBounds(109, 190, 243, 23);
    contentPane.add(chckbxGetSecureFiles);
    chckbxGetSecureFiles.setOpaque(false);

    chckbxMd5 = new JCheckBox("MD5 Hash Value");
    chckbxMd5.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.MD5);
            } else {
                ArgList.remove(SDConstant.MD5);
            }
        }
    });
    chckbxMd5.setBounds(109, 216, 243, 23);
    contentPane.add(chckbxMd5);
    chckbxMd5.setOpaque(false);

    chckbxDbdetails = new JCheckBox("Datasource Details");
    chckbxDbdetails.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.DATASOURCE);
            } else {
                ArgList.remove(SDConstant.DATASOURCE);
            }
        }
    });
    chckbxDbdetails.setBounds(109, 294, 243, 23);
    contentPane.add(chckbxDbdetails);
    chckbxDbdetails.setOpaque(false);

    chckbxLicense = new JCheckBox("License File");
    chckbxLicense.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.LICENSE);
            } else {
                ArgList.remove(SDConstant.LICENSE);
            }
        }
    });
    chckbxLicense.setBounds(109, 164, 243, 23);
    contentPane.add(chckbxLicense);
    chckbxLicense.setOpaque(false);

    chckbxProcesslist = new JCheckBox("Running Process");
    chckbxProcesslist.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.RUNNING_TASK);
            } else {
                ArgList.remove(SDConstant.RUNNING_TASK);
            }
        }
    });
    chckbxProcesslist.setBounds(109, 242, 243, 23);
    contentPane.add(chckbxProcesslist);
    chckbxProcesslist.setOpaque(false);

    chckbxTomcatxml = new JCheckBox("XML files from Tomcat");
    chckbxTomcatxml.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.FILE);
                tomcatXml = true;
            } else {
                ArgList.remove(SDConstant.FILE);
                tomcatXml = false;
            }
        }
    });
    chckbxTomcatxml.setBounds(377, 242, 248, 23);
    contentPane.add(chckbxTomcatxml);
    chckbxTomcatxml.setOpaque(false);

    chckbxServerXml = new JCheckBox("XML files from Server");
    chckbxServerXml.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.FILE);
                serverXml = true;
            } else {
                ArgList.remove(SDConstant.FILE);
                serverXml = false;
            }
        }
    });
    chckbxServerXml.setBounds(377, 216, 248, 23);
    contentPane.add(chckbxServerXml);
    chckbxServerXml.setOpaque(false);

    chckbxGetBatfiles = new JCheckBox("Start up files from server");
    chckbxGetBatfiles.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.FILE);
                serverBatFile = true;
            } else {
                ArgList.remove(SDConstant.FILE);
                serverBatFile = false;
            }
        }
    });
    chckbxGetBatfiles.setBounds(377, 268, 248, 23);
    contentPane.add(chckbxGetBatfiles);
    chckbxGetBatfiles.setOpaque(false);

    chckbxServerproperties = new JCheckBox("Properites files from server");
    chckbxServerproperties.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {

            if (e.getStateChange() == ItemEvent.SELECTED) {
                ArgList.add(SDConstant.FILE);
                serverProrperties = true;
            } else {
                ArgList.remove(SDConstant.FILE);
                serverProrperties = false;
            }
        }
    });
    chckbxServerproperties.setBounds(377, 294, 248, 23);
    contentPane.add(chckbxServerproperties);
    chckbxServerproperties.setOpaque(false);

    btnNewButton = new JButton("Package");
    btnNewButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent arg0) {

            try {

                if (installType.equalsIgnoreCase("Manual")) {

                    if (prop.getProperty(SDConstant.BI_TOM_PATH) == null) {
                        JOptionPane.showMessageDialog(contentPane, SDConstant.ERROR_12, "Inane error",
                                JOptionPane.ERROR_MESSAGE);
                    } else {

                        WEB_XML = new StringBuilder();
                        WEB_XML.append(prop.getProperty(SDConstant.BI_TOM_PATH)).append(File.separator)
                                .append(SDConstant.WEB_APP).append(File.separator).append(SDConstant.PENTAHO)
                                .append(File.separator).append(SDConstant.WEB_INF).append(File.separator)
                                .append(SDConstant.WEB_XML);

                        PENTAHO_SOLU_PATH = getSolutionPath("biserver", WEB_XML.toString());
                        prop.put(SDConstant.PENTAHO_SOLU_PATH, PENTAHO_SOLU_PATH);
                        prop.put(SDConstant.BI_PATH, PENTAHO_SOLU_PATH);
                    }

                }

                if (prop.getProperty(SDConstant.BI_PATH) == null) {
                    JOptionPane.showMessageDialog(contentPane, SDConstant.ERROR_1, "Inane error",
                            JOptionPane.ERROR_MESSAGE);
                }
                if (prop.getProperty(SDConstant.BI_TOM_PATH) == null) {
                    JOptionPane.showMessageDialog(contentPane, SDConstant.ERROR_12, "Inane error",
                            JOptionPane.ERROR_MESSAGE);
                }
                disableAll();
                setBIServerPath(prop);
                final String data = textFieldBrowser.getText();
                if (!data.equalsIgnoreCase(null)) {
                    ArgList.add(SDConstant.BROWSER);
                }

                String[] array = new String[ArgList.size()];

                int count = 0;
                for (int i = 0; i < ArgList.size(); i++) {

                    String retName = ArgList.get(i);
                    if (retName.equals("file")) {
                        if (count == 0) {
                            array[i] = retName;
                            count++;
                        }
                    } else {
                        array[i] = retName;
                    }

                }

                ApplicationContext context = new ClassPathXmlApplicationContext(SDConstant.SPRNG_FILE_NAME);

                factory = (CofingRetrieverFactory) context.getBean("cofingRetrieverFactory");
                ConfigRetreiver[] config = factory.getConfigRetrevier(array);

                ExecutorService service = Executors.newFixedThreadPool(10);

                for (final ConfigRetreiver configobj : config) {
                    if (null != configobj) {
                        configobj.setBISeverPath(prop);
                        configobj.setServerName("biserver");

                        if (installType.equalsIgnoreCase("Installer")) {
                            configobj.setInstallType("Installer");
                        } else if (installType.equalsIgnoreCase("Archive")) {
                            configobj.setInstallType("Archive");
                        } else if (installType.equalsIgnoreCase("Manual")) {
                            configobj.setInstallType("Manual");
                        }

                        if (configobj instanceof FileRetriever) {
                            configobj.setBidiXml(serverXml);
                            configobj.setBidiBatFile(serverBatFile);
                            configobj.setBidiProrperties(serverProrperties);
                            configobj.setTomcatXml(tomcatXml);
                        }
                        if (configobj instanceof BrowserInfoRetriever) {
                            configobj.setBrowserInfo(data);
                        }

                        service.execute(new Runnable() {
                            public void run() {
                                if (null != configobj)
                                    configobj.readAndSaveConfiguration(prop);
                            }
                        });
                    }
                }
                btnNewButton.setVisible(false);
                progressBar.setVisible(true);
                ProgressThread thread = new ProgressThread();
                thread.setSupport(getSupport());
                thread.setProp(prop);
                new Thread(thread).start();

                service.shutdown();
            } catch (Exception e1) {
                e1.printStackTrace();
            }

        }

    });

    chckbxSelectAll = new JCheckBox("Select/ De-select");
    chckbxSelectAll.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                selectAll();
            } else {
                deSelectAll();
            }
        }
    });

    chckbxSelectAll.setBounds(46, 138, 201, 23);
    chckbxSelectAll.setOpaque(false);
    contentPane.add(chckbxSelectAll);
    btnNewButton.setForeground(SystemColor.infoText);
    btnNewButton.setBounds(10, 430, 639, 37);
    contentPane.add(btnNewButton);
    chckbxServerproperties.setOpaque(false);

    JLabel lblAttach = new JLabel("Attach Artifact");
    lblAttach.setHorizontalAlignment(SwingConstants.LEFT);
    lblAttach.setBounds(32, 335, 177, 23);
    contentPane.add(lblAttach);
    lblAttach.setOpaque(false);

    JButton btnNewButtonBrowse = new JButton("Browse");
    btnNewButtonBrowse.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent arg0) {
            saveSelectedFile(prop);

            JFrame parentFrame = new JFrame();
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setDialogTitle("Specify a file to save");
            fileChooser.setMultiSelectionEnabled(true);

            int userSelection = fileChooser.showSaveDialog(parentFrame);

            if (userSelection == JFileChooser.APPROVE_OPTION) {
                fileToSave = fileChooser.getSelectedFiles();
                for (int i = 0; i < fileToSave.length; i++) {
                    File file = fileToSave[i];
                    String artifactpath = file.getAbsolutePath();

                    File f = new File(artifactpath);
                    String absolutefilename = f.getName();
                    String filename = ArtifactsDirectory.concat(absolutefilename);
                    CopyFile artifactcopy = new CopyFile(artifactpath, filename);
                    try {
                        artifactcopy.copy();
                    } catch (Exception e1) {
                        e1.printStackTrace();
                    }

                }
                uploadedFiles();

                rowList = new JList(model);
                listScrollPane.setViewportView(rowList);
                panel.add(listScrollPane);

            }
            rowList.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    lblDelete.setVisible(true);
                }
            });

        }
    });
    btnNewButtonBrowse.setBounds(208, 335, 104, 23);
    contentPane.add(btnNewButtonBrowse);
    btnNewButtonBrowse.setOpaque(false);

    textFieldBrowser = new JTextField();
    textFieldBrowser.setBounds(208, 364, 441, 23);
    contentPane.add(textFieldBrowser);
    textFieldBrowser.setColumns(10);

    progressBar = new JProgressBar(0, 100);
    progressBar.setBounds(8, 437, 639, 24);
    progressBar.setVisible(false);
    progressBar.setStringPainted(true);
    contentPane.add(progressBar);

    JLabel lblBrowserInformation = new JLabel("Browser Information");
    lblBrowserInformation.setHorizontalAlignment(SwingConstants.LEFT);
    lblBrowserInformation.setLabelFor(textFieldBrowser);
    lblBrowserInformation.setBounds(32, 368, 174, 14);
    contentPane.add(lblBrowserInformation);

    panel = new JPanel();
    panel.setBounds(423, 325, 127, 33);
    contentPane.add(panel);
    panel.setLayout(null);

    listScrollPane = new JScrollPane();
    listScrollPane.setBounds(0, 0, 127, 33);
    panel.add(listScrollPane);

    lblDelete = new JLabel("");
    lblDelete.setBounds(552, 325, 22, 23);
    lblDelete.setVisible(false);
    lblDelete.setIcon(
            new ImageIcon(SDSupportUtility.class.getResource("/org/pentaho/support/standalone/remove.png")));
    contentPane.add(lblDelete);
    lblDelete.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            int option = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete this file ?");
            if (option == JOptionPane.YES_OPTION) {
                String sel = rowList.getSelectedValue().toString();
                String selected = dir + "/" + sel;
                File fileExists = new File(selected);
                fileExists.delete();
                model.remove(sel.indexOf(sel));
                lblDelete.setVisible(false);

            }
        }
    });

    JLabel instalType = new JLabel("Installation Type : ");
    instalType.setBounds(32, 395, 177, 23);
    instalType.setVisible(true);
    contentPane.add(instalType);

    ButtonGroup btnGrp = new ButtonGroup();

    rdbtnInstaller = new JRadioButton("Installer");
    rdbtnInstaller.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            installType = "Installer";
        }
    });
    rdbtnInstaller.setBounds(208, 395, 104, 23);
    rdbtnInstaller.setSelected(true);
    contentPane.add(rdbtnInstaller);
    btnGrp.add(rdbtnInstaller);

    rdbtnArchive = new JRadioButton("Archive");
    rdbtnArchive.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            installType = "Archive";
        }
    });
    rdbtnArchive.setBounds(333, 395, 104, 23);
    contentPane.add(rdbtnArchive);
    btnGrp.add(rdbtnArchive);

    rdbtnManual = new JRadioButton("Manual");
    rdbtnManual.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            installType = "Manual";
        }
    });
    rdbtnManual.setBounds(460, 395, 127, 27);
    contentPane.add(rdbtnManual);
    btnGrp.add(rdbtnManual);

    JLabel lblBackground = new JLabel();
    lblBackground.setIcon(new ImageIcon(
            SDSupportUtility.class.getResource("/org/pentaho/support/standalone/login-crystal-bg.jpg")));
    lblBackground.setBackground(SystemColor.controlHighlight);
    lblBackground.setHorizontalAlignment(SwingConstants.CENTER);
    lblBackground.setBounds(0, 0, 659, 488);
    contentPane.add(lblBackground);
}

From source file:org.alfresco.repo.transaction.RetryingTransactionHelperTest.java

@SuppressWarnings("unchecked")
private void runThreads(final RetryingTransactionHelper txnHelper, final List<Throwable> caughtExceptions,
        final Pair<Integer, Integer>... startDurationPairs) {
    ExecutorService executorService = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS,
            new ArrayBlockingQueue<Runnable>(10));

    class Work implements Runnable {
        private final CountDownLatch startLatch;
        private final long endTime;

        public Work(CountDownLatch startLatch, long endTime) {
            this.startLatch = startLatch;
            this.endTime = endTime;
        }// w  w  w  .  j av  a2  s  .  c  o m

        public void run() {
            try {
                txnHelper.doInTransaction(new RetryingTransactionCallback<Void>() {

                    public Void execute() throws Throwable {
                        // Signal that we've started
                        startLatch.countDown();

                        long duration = endTime - System.currentTimeMillis();
                        if (duration > 0) {
                            Thread.sleep(duration);
                        }
                        return null;
                    }
                });
            } catch (Throwable e) {
                caughtExceptions.add(e);
                // We never got a chance to signal we had started so do it now
                if (startLatch.getCount() > 0) {
                    startLatch.countDown();
                }
            }
        }
    }
    ;

    // Schedule the transactions at their required start times
    long startTime = System.currentTimeMillis();
    long currentStart = 0;
    for (Pair<Integer, Integer> pair : startDurationPairs) {
        int start = pair.getFirst();
        long now = System.currentTimeMillis();
        long then = startTime + start;
        if (then > now) {
            try {
                Thread.sleep(then - now);
            } catch (InterruptedException e) {
            }
            currentStart = start;
        }
        CountDownLatch startLatch = new CountDownLatch(1);
        Runnable work = new Work(startLatch, startTime + currentStart + pair.getSecond());
        executorService.execute(work);
        try {
            // Wait for the thread to get up and running. We need them starting in sequence
            startLatch.await(60, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
        }
    }
    // Wait for the threads to have finished
    executorService.shutdown();
    try {
        executorService.awaitTermination(60, TimeUnit.SECONDS);
    } catch (InterruptedException e) {
    }

}