Java ThreadPool Example

Some people asked at this forum: "How to write Java Threadpool?" Here is an example, which I have tested on the computer with two CPU. This example also runs well with J#.
TPTest.java
package demo.test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Calendar;
import thread.util.ThreadPool;
class ShutdownHook extends Thread {
    public void run() {
        try {
            MyRunnable.fout.flush();
            Thread.sleep(1000);
            MyRunnable.fout.close();
        catch (Exception e) {
            e.printStackTrace();
class MyRunnable implements Runnable {
    public static File file;
    public static FileWriter fout;
     public static PrintStream out;
    static {
        try {
            file = new File(".\\ThreadPool.log");
            fout = new FileWriter(file);
               out = System.out;
            //Uncomment the next line in J#
            //Runtime.getRuntime().runFinalizersOnExit(true);
            //Comment the next line in J#
            Runtime.getRuntime().addShutdownHook(new ShutdownHook());
        catch (IOException e) {
            e.printStackTrace();
    static int n = 0;
    int i;
    public MyRunnable(int i) {
        this.i = i;
    public void run() {
        try {
            synchronized(fout) {
                n++;
                fout.write("Sample No." + n + "\t" + Calendar.getInstance().getTime().getMinutes() + ":" +
                Calendar.getInstance().getTime().getSeconds() + ":" +
                Calendar.getInstance().get(Calendar.MILLISECOND) +  
                ":" + "Executed: " + this + Thread.currentThread() + "\r\n");
                    out.println("Sample No." + n + "\t" + Calendar.getInstance().getTime().getMinutes() + ":" +
                Calendar.getInstance().getTime().getSeconds() + ":" +
                Calendar.getInstance().get(Calendar.MILLISECOND) +  
                ":" + "Executed: " + this + Thread.currentThread());
        catch (IOException e) {
            e.printStackTrace();
        synchronized(this) {
            notify();
    public String toString() {
        return "Task No." + i;
public class TPTest {
    public static void main(String[] args) {
        ThreadPool thp = new ThreadPool(100);
        int count = 10000;
        for (int i = 0; i < count; i++) {
            if(i == count - 1)
                // Wait for the last Invoke
                ThreadPool.invokeAndWait(thp, new MyRunnable(i));
            else
                ThreadPool.invokeLater(thp, new MyRunnable(i));
        try {
            MyRunnable.fout.flush();
            MyRunnable.fout.close();
        }catch(Exception e) {
        System.exit(0);
Queue.java
package thread.util;
import java.util.Enumeration;
class NoSuchElementException extends RuntimeException {
    public NoSuchElementException() {
        super();
    public NoSuchElementException(String s) {
        super(s);
class QueueElement {
    QueueElement next = null;
    QueueElement prev = null;
    Object obj = null;
    QueueElement(Object obj) {
        this.obj = obj;
    public String toString() {
        return "QueueElement[obj="
            + obj
            + (prev == null ? " null" : " prev")
            + (next == null ? " null" : " next")
            + "]";
final class LIFOQueueEnumerator implements Enumeration {
    Queue queue;
    QueueElement cursor;
    LIFOQueueEnumerator(Queue q) {
        queue = q;
        cursor = q.head;
    public boolean hasMoreElements() {
        return (cursor != null);
    public Object nextElement() {
        synchronized (queue) {
            if (cursor != null) {
                QueueElement result = cursor;
                cursor = cursor.next;
                return result.obj;
        throw new NoSuchElementException("NoSuchElement");
final class FIFOQueueEnumerator implements Enumeration {
    Queue queue;
    QueueElement cursor;
    FIFOQueueEnumerator(Queue q) {
        queue = q;
        cursor = q.tail;
    public boolean hasMoreElements() {
        return (cursor != null);
    public Object nextElement() {
        synchronized (queue) {
            if (cursor != null) {
                QueueElement result = cursor;
                cursor = cursor.prev;
                return result.obj;
        throw new NoSuchElementException("FIFOQueueEnumerator");
public class Queue {
    int length = 0;
    QueueElement head = null;
    QueueElement tail = null;
    public Queue() {
    public synchronized void enqueue(Object obj) {
        QueueElement newElt = new QueueElement(obj);
        if (head == null) {
            head = newElt;
            tail = newElt;
            length = 1;
        else {
            newElt.next = head;
            head.prev = newElt;
            head = newElt;
            length++;
    public synchronized Object dequeue() {
        QueueElement elt = tail;
        tail = elt.prev;
        if (tail == null) {
            head = null;
        else {
            tail.next = null;
        length--;
        return elt.obj;
    public synchronized boolean isEmpty() {
        return (tail == null);
    public final synchronized Enumeration elements() {
        return new LIFOQueueEnumerator(this);
    public final synchronized Enumeration reverseElements() {
        return new FIFOQueueEnumerator(this);
    public synchronized void dump(String msg) {
        System.err.println(">> " + msg);
        System.err.println(
                + length
                + " elt(s); head = "
                + (head == null ? "null" : (head.obj) + "")
                + " tail = "
                + (tail == null ? "null" : (tail.obj) + ""));
        QueueElement cursor = head;
        QueueElement last = null;
        while (cursor != null) {
            System.err.println("  " + cursor);
            last = cursor;
            cursor = cursor.next;
        if (last != tail) {
            System.err.println("  tail != last: " + tail + ", " + last);
        System.err.println("]");
QueueException.java
package thread.util;
public class QueueException extends RuntimeException {
ThreadPool.java
package thread.util;
* A thread pool with a bounded task queue and fixed number of worker threads.
public class ThreadPool {
    public static ThreadPool currentThreadPool = null;
    public Queue queue;
    public ThreadPool(int threads) {
        queue = new Queue();
        /* create the worker threads */
        for (int i = 0; i < threads; ++i) {
            Thread t = new Thread(new WorkerThread(), "WorkerThread: " + (i + 1));
            t.setDaemon(true);
            t.start();
     * Queues a task to be executed by this ThreadPool. If the task queue is
     * full, the task will run in the calling thread. (Could easily be modified
     * to throw an exception instead.)
    public void doTask(Runnable task) {
        synchronized (queue) {
            queue.enqueue(task);
            queue.notify();
     * Tests if the task queue is empty.  Useful if you want to wait for all
     * queued tasks to complete before terminating your program.
    public boolean queueEmpty() {
        synchronized (queue) {
            return queue.isEmpty();
    private class WorkerThread implements Runnable {
        public void run() {
            Runnable task;
            while (true) {
                task = null;
                synchronized (queue) {
                    try {
                        if (queue.isEmpty()) {
                            queue.wait();
                        else {
                            task = (Runnable)queue.dequeue();
                    catch (InterruptedException e) {
                        break;
                if (task != null) {
                    task.run();
    } /* end inner class WorkerThread */
    public static void invokeLater(ThreadPool thp, Runnable task) {
        thp.doTask(task);
    public static void invokeAndWait(ThreadPool thp, Runnable task) {
        TaskWrapper tw = new TaskWrapper(task);
        synchronized(tw.task) {
            try {
                thp.doTask(tw);
                tw.task.wait();
            catch (InterruptedException e) {
            tw = null;
    public static void invokeLater(Runnable task) {
        if(ThreadPool.currentThreadPool == null) {
            ThreadPool.currentThreadPool = new ThreadPool(20);
        ThreadPool.currentThreadPool.doTask(task);
    public static void invokeAndWait(Runnable task) {
        if(ThreadPool.currentThreadPool == null) {
            ThreadPool.currentThreadPool = new ThreadPool(20);
        TaskWrapper tw = new TaskWrapper(task);
        synchronized(tw.task) {
            try {
                ThreadPool.currentThreadPool.doTask(tw);
                tw.task.wait();
            catch (InterruptedException e) {
            tw = null;
} /* end class ThreadPool */
class TaskWrapper implements Runnable {
    public Runnable task;
    public TaskWrapper(Runnable task) {
        this.task = task;
    public void run() {
        synchronized(task) {
            task.run();
            task.notify();

Thanks for the example. I was wondering how to do this.
I am running it right now on Fedora Linux.
When I run the demo TPTest.java
as written
ThreadPool thp = new ThreadPool(100);
int count = 10000;
I get and error at the very end of the run like this :
Sample No.10000     32:36:289:Executed: Task No.652Thread[WorkerThread: 10,5,main]
java.io.IOException: Stream closed
     at sun.nio.cs.StreamEncoder.ensureOpen(StreamEncoder.java:38)
     at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:151)
     at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:213)
     at demo.test.ShutdownHook.run(TPTest.java:14)
Is this correct behaviour?
General this the only error I see. If I start changing the count and Threadpool size to
other combinations, I occasionally get other errors similar to this one as well.
java.io.IOException: Stream closed
     at sun.nio.cs.StreamEncoder.ensureOpen(StreamEncoder.java:38)
     at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:129)
     at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:146)
     at java.io.OutputStreamWriter.write(OutputStreamWriter.java:204)
     at java.io.Writer.write(Writer.java:126)
     at demo.test.MyRunnable.run(TPTest.java:53)
     at thread.util.ThreadPool$WorkerThread.run(ThreadPool.java:58)
     at java.lang.Thread.run(Thread.java:534)
Is there a way to increase thread size with java on Fedora Linux (Core 3)?
Would like to know. This example was interesting to me because I am trying to push
the limit for load testing purposes.
Thanks again for the example. Let me know if you have any updates to this one.

Similar Messages

  • Simple Java DB example

    I am using Java 1.6 and Eclipse Galelio on Vista, Do I need to configure anything is there any story of setting path?
    How to check my Java DB is working or not or everything is fine or not?
    I found many totorial with simple Java DB example but they seem dealing with previous version of JDK, I guess SUN too on http://java.sun.com/developer/technicalArticles/J2SE/Desktop/javadb/ , kindly provide me the simplest example which uses Java DB.
    I am not able to figure out the whole thing of JAVA DB , how it works, in plain language I want to know is there any way of interacting with database from Command prompt? If so how?

    When I am running a simpleApp.java
    I am getting this error:
    Unable to load the JDBC driver org.apache.derby.jdbc.EmbeddedDriver
    Please check your CLASSPATH.
    java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at SimpleApp.loadDriver(SimpleApp.java:414)
         at SimpleApp.go(SimpleApp.java:125)
         at SimpleApp.main(SimpleApp.java:93)
    ----- SQLException -----
    SQL State: 08001
    Error Code: 0
    Message: No suitable driver found for jdbc:derby:derbyDB;create=true
    SimpleApp starting in embedded mode
    SimpleApp finished

  • UML diagrams for Java petstore example

    Hi,
    In this forum and elsewhere I've notice requests for the UML diagrams for the java petstore example. I've posted some uml diagrams at
    http://weblog.neeraj.name/weblog/2004/9/9/java-petstore-uml-diagrams.html
    Your comments are welcome.
    thanks.
    - Neeraj
    http://weblog.neeraj.name

    Hi,
    I browsed through some of your UML. Its a great start! Would you be interested in starting a project on java.net and hosting your uml there? We now have the BluePrints projects out on java.net https://blueprints.dev.java.net/ and would like to encourage others to add their projects as well.
    Lots of people have done cool stuff with Java Petstore and other blueprints projects, and lots of people have created additions to these projects. These UML diagrams would seem to be a great addition to the J2EE community on java.net http://community.java.net/java-enterprise/.
    Its easy to join java.net and to create a new project. They give you a cvs repository where you can store your uml diagrams. We could include a reference to it from the blueprints since it is really useful supplemental material. By making it a project as part of the J2EE community on java.net it makesd it accessible to a larger audience of people. Not everyone will read this forum, and lots more people might find your project useful. So if you wish we had more UML for the Petstore, ....then now is your chance to make a difference :-) Maybe a project called UML4Petstore?
    This page has some explanations of how to add a project if interested.
    https://java-enterprise.dev.java.net/
    hope that helps,
    Sean

  • Whenever I use something which uses Java (for example, an online game) and then click the address bar, it seems that the address bar is disabled.

    Whenever I use something which uses Java (for example, an online game) and then click the address bar, it seems that the address bar is disabled. I cannot highlight or type in the address bar unless I interact with another program and then switch back to Firefox. When I interact with Java again, the same problem persists! Help!
    Sorry, I didn't know what category this should be under, but it's urgent.

    Perform the suggestions mentioned in the following articles:
    * [https://support.mozilla.com/en-US/kb/Template:clearCookiesCache/ Clear Cookies & Cache]
    * [[Troubleshooting extensions and themes]]
    Check and tell if its working.
    Some of your Firefox Plugins are out-dated
    * Update All your Firefox Plugins -> [https://www.mozilla.org/en-US/plugincheck/]
    * '''When Downloading Plugins Update setup files, Remove Checkmark from Downloading other Optional Softwares with your Plugins (e.g. Toolbars, McAfee, Google Chrome, etc.)'''

  • A Toplink Java code example in Jdev 10.1.2

    Hello every body
    I have just begun using Toplink 10g in Jdev 10.1.2, and I want examples of Java code to insert, edit and show information from struts application whose model is Toplink.
    Thanks

    If you are using toplink 9045 which ships with Jdev 1012, and just starting out then you might consider using Jdev1013 along with toplink 1013 since there is some measurable difference between the two releases.
    Information about toplink and examples.
    http://www.oracle.com/technology/products/ias/toplink/examples/index.html
    http://www.oracle.com/technology/products/ias/toplink/technical/index.html

  • Question about Java Sound example?

    Hello,
    I found this example AudioPlayer, when searching for an example of how to play .wav files in Java.
    The code seems quite long, and wondered if anyone could advise if this is the best way to play a wav file?
    And could anyone explain if the EXTERNAL_BUFFER_SIZE should allows be set to 128000;
    Thank you
    import java.io.File;
    import java.io.IOException;
    import javax.sound.sampled.AudioFormat;
    import javax.sound.sampled.AudioInputStream;
    import javax.sound.sampled.AudioSystem;
    import javax.sound.sampled.DataLine;
    import javax.sound.sampled.LineUnavailableException;
    import javax.sound.sampled.SourceDataLine;
    public class SimpleAudioPlayer
         private static final int     EXTERNAL_BUFFER_SIZE = 128000;
         public static void main(String[] args)
                We check that there is exactely one command-line
                argument.
                If not, we display the usage message and exit.
              if (args.length != 1)
                   printUsageAndExit();
                Now, that we're shure there is an argument, we
                take it as the filename of the soundfile
                we want to play.
              String     strFilename = args[0];
              File     soundFile = new File(strFilename);
                We have to read in the sound file.
              AudioInputStream     audioInputStream = null;
              try
                   audioInputStream = AudioSystem.getAudioInputStream(soundFile);
              catch (Exception e)
                     In case of an exception, we dump the exception
                     including the stack trace to the console output.
                     Then, we exit the program.
                   e.printStackTrace();
                   System.exit(1);
                From the AudioInputStream, i.e. from the sound file,
                we fetch information about the format of the
                audio data.
                These information include the sampling frequency,
                the number of
                channels and the size of the samples.
                These information
                are needed to ask Java Sound for a suitable output line
                for this audio file.
              AudioFormat     audioFormat = audioInputStream.getFormat();
                Asking for a line is a rather tricky thing.
                We have to construct an Info object that specifies
                the desired properties for the line.
                First, we have to say which kind of line we want. The
                possibilities are: SourceDataLine (for playback), Clip
                (for repeated playback)     and TargetDataLine (for
                recording).
                Here, we want to do normal playback, so we ask for
                a SourceDataLine.
                Then, we have to pass an AudioFormat object, so that
                the Line knows which format the data passed to it
                will have.
                Furthermore, we can give Java Sound a hint about how
                big the internal buffer for the line should be. This
                isn't used here, signaling that we
                don't care about the exact size. Java Sound will use
                some default value for the buffer size.
              SourceDataLine     line = null;
              DataLine.Info     info = new DataLine.Info(SourceDataLine.class,
                                                                 audioFormat);
              try
                   line = (SourceDataLine) AudioSystem.getLine(info);
                     The line is there, but it is not yet ready to
                     receive audio data. We have to open the line.
                   line.open(audioFormat);
              catch (LineUnavailableException e)
                   e.printStackTrace();
                   System.exit(1);
              catch (Exception e)
                   e.printStackTrace();
                   System.exit(1);
                Still not enough. The line now can receive data,
                but will not pass them on to the audio output device
                (which means to your sound card). This has to be
                activated.
              line.start();
                Ok, finally the line is prepared. Now comes the real
                job: we have to write data to the line. We do this
                in a loop. First, we read data from the
                AudioInputStream to a buffer. Then, we write from
                this buffer to the Line. This is done until the end
                of the file is reached, which is detected by a
                return value of -1 from the read method of the
                AudioInputStream.
              int     nBytesRead = 0;
              byte[]     abData = new byte[EXTERNAL_BUFFER_SIZE];
              while (nBytesRead != -1)
                   try
                        nBytesRead = audioInputStream.read(abData, 0, abData.length);
                   catch (IOException e)
                        e.printStackTrace();
                   if (nBytesRead >= 0)
                        int     nBytesWritten = line.write(abData, 0, nBytesRead);
                Wait until all data are played.
                This is only necessary because of the bug noted below.
                (If we do not wait, we would interrupt the playback by
                prematurely closing the line and exiting the VM.)
                Thanks to Margie Fitch for bringing me on the right
                path to this solution.
              line.drain();
                All data are played. We can close the shop.
              line.close();
                There is a bug in the jdk1.3/1.4.
                It prevents correct termination of the VM.
                So we have to exit ourselves.
              System.exit(0);
         private static void printUsageAndExit()
              out("SimpleAudioPlayer: usage:");
              out("\tjava SimpleAudioPlayer <soundfile>");
              System.exit(1);
         private static void out(String strMessage)
              System.out.println(strMessage);
    }

    I didnot go thru the code you posted but I know that the following workstry {
            // From file
            AudioInputStream stream = AudioSystem.getAudioInputStream(new File("audiofile"));
            // From URL
            stream = AudioSystem.getAudioInputStream(new URL("http://hostname/audiofile"));
            // At present, ALAW and ULAW encodings must be converted
            // to PCM_SIGNED before it can be played
            AudioFormat format = stream.getFormat();
            if (format.getEncoding() != AudioFormat.Encoding.PCM_SIGNED) {
                format = new AudioFormat(
                        AudioFormat.Encoding.PCM_SIGNED,
                        format.getSampleRate(),
                        format.getSampleSizeInBits()*2,
                        format.getChannels(),
                        format.getFrameSize()*2,
                        format.getFrameRate(),
                        true);        // big endian
                stream = AudioSystem.getAudioInputStream(format, stream);
            // Create the clip
            DataLine.Info info = new DataLine.Info(
                Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));
            Clip clip = (Clip) AudioSystem.getLine(info);
            // This method does not return until the audio file is completely loaded
            clip.open(stream);
            // Start playing
            clip.start();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        } catch (LineUnavailableException e) {
        } catch (UnsupportedAudioFileException e) {
        }

  • OS level calls in Java.. example.

    Simple and perhaps idiotic question... but here it goes.
    Is there a way to make OS level calls in Java (i.e such as the cp, mv or ls/dir commands)?
    What class due I need to instantiate do to this? and is it the same for UNIX and win32 systems?
    Here is what I attempted to do:
    ================
    import java.io.*;
    public class Test {
    private static void main(String args[]) {
    String cmd[] =
    {"copy", "c:\\temp\\test.txt", "c:\\temp\\test2.txt"};
    try {
    Process p = Runtime.getRuntime().exec("copy test.txt test2.txt");
    p = Runtime.getRuntime().exec(cmd);
    } catch (Exception e) {
    e.printStackTrace();
    However, the above code results in the following error at runtime...
    =============
    java.io.IOException: CreateProcess: copy c:\temp\test.txt c:\temp\test2.txt error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:61)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:546)
    at java.lang.Runtime.exec(Runtime.java:413)
    at java.lang.Runtime.exec(Runtime.java:356)
    at java.lang.Runtime.exec(Runtime.java:320)
    at Test.main(Test.java:7)
    ==============
    Thoughts?
    Any help is greatly appreciated.
    Regards
    echardrd

    Almost right...
    "copy" is a shell builtin for Windows, so you need to call it as an argument to cmd.exe (or command.com on older systems). E.g. in Win2000 you can go:
    Runtime.getRuntime().exec( "cmd /c copy c:\\test1.txt c:\\test2.txt" );Where the /c is the parameter to tell cmd to carry out the given command. You could run this with the "start" command to push it into the background.
    Unix behaviour is roughly similar: cp is a Bash builtin for example, so you probably need to execute a shell process and pass it cp (I'm not sure about that one, I didn't test it)

  • Berkeley DB master-slave replication basic java code example

    Hi,
    I am new user of berkeley db and I have limited knowledge of Java programming. Can someone help me with basic Java example code of how to do master-slave replication without elections.
    Thanx,
    Jani

    Hello,
    Please clarify a few points about your program:
    1. What platform and Berkeley DB version are you using?
    2. Are you planning on using the replication framework
    or base replication API for your application?
    3. When you say you want replication without elections,
    what exactly does that mean. For example, if you are using
    the replication framework elections are held transparently
    without any input from your application's code. In this case,
    DB will determine which environment is the master and which
    are replicas. Is that what you are thinking about or
    something else?
    Thanks,
    Sandra

  • Enum - core java II example

    hi
    the following code is an example taken from 'core java II'-book.
    what i don't understand is where the enum constructor is called
    to set the abbreviation field
    anyone care to explain ?
    thanks
    import java.util.*;
    public class EnumTest {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            System.out.print("Enter a size: (SMALL, MEDIUM, LARGE, EXTRA_LARGE) ");
            String input = in.next().toUpperCase();
            Size size = Enum.valueOf(Size.class, input);
            System.out.println("size=" + size);
            System.out.println("abbreviation=" + size.getAbbreviation());
            if (size == Size.EXTRA_LARGE) {
                System.out.println("Good job--you paid attention to the _.");
    enum Size {
        SMALL("S"), MEDIUM("M"), LARGE("L"), EXTRA_LARGE("XL");
        private Size(String abbreviation) {
            this.abbreviation = abbreviation;
        public String getAbbreviation() {
            return abbreviation;
        private String abbreviation;
    }

    so from what i get here is that
    SMALL("S"),MEDIUM("M"),LARGE("L"); are the constructors from where abbreviations are taken.
    I want to clear one more doubt.
    private Size(String abbreviation) {
            this.abbreviation = abbreviation;1. This is also a constructor right ? If yes then, what was the need that the author made this constructor private ?
    2. Why public modifier is not allowed there ?
    3. Size s = Enum.valueOf(Size.class,input);Over here what is the role of argument Size.class ?
    4. enum size
    Size s = Enum.valueOf(Size.class,input);In the first code enum's e is small but in the second code Enum's E is capital. How so ?
    Edited by: levislover on Jun 16, 2010 11:29 PM

  • Java sax example

    Hello All
    I need a xml, sax example.....
    If I have a XML document like
    Input.xml
    <film>
         <artistes>
              <name>Art1</name>
              <name>Art2</name>
         <artistes>
         <technicians>
              <tech> Camera </tech>
              <tech> Direction </tech>
         <technicians>
    </film>
    I want the xml to be verified against a DTD (please come up with the DTD for the above xml, sorry). And the output xml should be of the form
    <finearts>
         <artistes>
              <name>Art1</name>
              <name>Art2</name>
         <artistes>
         <technicians>
              <tech> Camera </tech>
              <tech> Direction </tech>
         <technicians>
    <finearts>
    Basically film node is replaced by finearts.
    I can appreciate if I can get a java program which does this.
    The java class should have 2 methods, one whch takes input xml as string, and the other which takes as filename. I need this to be using SAX parser.
    Repeating
    1. Take xmlinput either as a string or as a file.
    2. Validate against DTD.
    3. Perform the transform.
    4. Write the result to a file.
    Thanks

    Forte can auto generate a sax parser for you. Just mount the correct directory and right click on the dtd, and select SAX handler wizard.

  • Algorithm / Java Code examples

    Hi there, is there anyway I can get simple algorithms, java examples of these below -
    Adjacency Matrix
    Transitive Closure Matrix
    Shortest-path algorithm
    DFS and BFS traversal
    Floyd all-pairs shortest path algorithm
    Topological Sort
    Reverse DFS Topological Sort
    I googled them but couldn't get enough success. Please help me out. Any suggestions would be appreciated. Thanks a lot!

    Continue googling, and add java to the search criteria. E.g.
    java Adjacency Matrix

  • ECM java client - example code

    Hi,
    Enviroment: ECM 11.x
    I need to write ADF application integrated wit ECM. Is there any public java codes with examples ? I mean somethink like examples for SOA Suite http://java.net/projects/oraclesoasuite11g/pages/Home covers e.g. example how to write custom worklist. My requairement is to write some functionality from ECM console, so it would be useful to have some java api usage examples.
    Kuba

    Actually, what workflows you intend to use? And, what's your use case what-so-ever?
    I hope I won't confuse you, but in fact, you could mean three things:
    - use UCM native (iDocScript workflows)
    - use BPEL workflows
    - use BPM workflows (as BPM Suite is now also part of the license)
    The last is completely driven from the BPM side, so there you don't need to do anything.
    The second works like this: you may define a criteria workflow which passes the item to a BPEL workflow. When BPEL finishes, it passes the workflow back to release the item. If you have samples for SOA Suite, you could reuse them.
    Only for UCM native workflows, you would need to write your own codes (calling services - most likely WS), but havinf the first two options, is it worth?

  • Executing java card examples

    morning mates;
    New to java card and I have been trying to run the examples with the javacard development kit,I have dowmloaded and extracted the kit set the JC_HOME environmental variable to my installation path and I get this error message on the command promp
    C:\java_card_kit-2_2_2\samples\src\demo\jcwde>jcwde jcwde.app
    'C:\Program' is not recognized as an internal or external command,
    operable program or batch file.
    pls what is it that I am doing wrong or I am not doing thanks

    Install the kit in another location than "Program Files", e.g. C:\JavaCard. It seems like the space in the path name isn't tolerated.

  • Compiling Java Bean Example FileUploadUtility

    Dear Oracle Gurus,
    Trying to compile the FileUploadUtility example I have some problems:
    It seems that the following libs are missing.
    import oracle.forms.*
    import oracle.ewt.*
    Do I need any additional libraries ?
    Is there any documentation how to compile the sample ?
    thank you for your help !
    Leopold Zyka
    [email protected]
    null

    Hi
    Yes I can find
    $ORACLE_HOME/forms60/java/ewt and
    $ORACLE_HOME/forms60/java/bali
    * I am using JDeveloper 3.2.3
    What do I have to do ?
    Is there any path I have to set to this package so that the import works ?
    * Where can I find the following package ?
    import oracle.forms.ui.VBean;
    import oracle.forms.ui.CustomEvent;
    import oracle.forms.handler.IHandler;
    import oracle.forms.properties.ID;
    regards, Leopold Zyka
    null

  • Java GUI examples?

    Hello,
    I am hoping someone can point me in the right direction. I have seen tons of examples of how to create text boxes, graphics, buttons and what not in Java. What I have not been able to find is an example of a program that actually calls other methods.
    I guess I am having a difficult time understanding how to apply the cool graphical elements to my already existing project. For example, I need to display a list of items stored in an array using a GUI.
    Do I create a seperate class for the GUI? or can I slap this code right into my main method?
    Thanks for all the help.
    Rgds,
    Paul

    Hi Icycool,
    I have seen these, thank you. What I am confused about is how to apply these to other code. I can run through the examples but I do not see how I can use these in an actual program.
    For instance. I have a main method which calls another class. I construct the objects from the class, create an array, and need to display this info in a GUI. It's nothing complicated.
    I just don't understand where to put the GUI code itself. Does that make sense?
    Thanks,
    Paul

Maybe you are looking for

  • Imac 350Mhz G3 Slot loading-Won't boot from cd's

    So here's what's going on So, I found this imac awhile back. (somebody was throwing it out) http://www.apple-history.com/?page=gallery&model=imacslot I plugged it in today(it uses the same cable as my summer 2000 indigo imac) and i turned it on, it m

  • IDOC-WS-IDOC-(no bpm) Possible??.

    Hi Experts, Please can anyone advise how to do the following scenario. 1.Outbound Idoc to Webservice. 2.Response of the webservice through PI should trigger an inbound idoc. Can this be done without a bpm??. I tried with a message interface MIOS with

  • Album FLow stopped working in iTunes

    All of a sudden Album flow says "Itunes is unable to browse album covers on this computer". I uninstalled and reinstalled iTunes and that was not help. I have it rebuild the library and that was not help. So what do I do now?

  • CS4 wont load - shut down Bridge? Help

    Newbie here Just rec. my CS4 and I am trying to install it and it keeps freezing and telling me that I need to turn off Bridge.  I did not know I turned it on and I sure dont know how to turn it off.... Anyone??? Sorry for the stupid-o question. Than

  • RAW Camera Format for webos like Apple can this with iPad?

    Hi all, is there a chance to get in the near future (eventually with the Touchpad Release) a Software to view Picture Raw Formats like Nikons nef, Canons crw and others? The Software for the "Apples iPad Camera Connection Kit" is continously updated