Package net.sf.antcontrib.util

Examples of net.sf.antcontrib.util.ThreadPool


        this.maxThreads = 5;
    }

    private void executeParallel(Vector tasks)
    {
        ThreadPool pool = new ThreadPool(maxThreads);
        Enumeration e = tasks.elements();
        Runnable r = null;
        Vector threads = new Vector();

        // start each task in it's own thread, using the
        // pool to ensure that we don't exceed the maximum
        // amount of threads
        while (e.hasMoreElements())
        {
            // Create the Runnable object
            final Task task = (Task)e.nextElement();
            r = new Runnable()
            {
                public void run()
                {
                    task.execute();
                }
            };

            // Get a thread, and start the task.
            // If there is no thread available, this will
            // block until one becomes available
            try
            {
                ThreadPoolThread tpt = pool.borrowThread();
                tpt.setRunnable(r);
                tpt.start();
                threads.addElement(tpt);
            }
            catch (Exception ex)
View Full Code Here

TOP

Related Classes of net.sf.antcontrib.util.ThreadPool

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.