Hi,

ASAIK the problem rests with the way Java interacts with it UI subsystem. For example
when you perform any operation that involve AWT, this presumable includes using any
Font object, all of the event pump threads start up. This is unavoidable until JDK 1.4
where it is possible to get a 'headless' version of AWT. (IE one that doesn't need to
talk to a window manager)

So why does this cause your program to not terminate? In previous version of Java
these threads where marked daemon which meant that Java would not consider them
significant when deciding whether to end the VM. (The VM will exit when there are no
non daemon threads running) But for one reason or another, I cannot remember what, the
AWT threads are now marked a non-daemon. This means that any program that involves the
UI in anyway needs to call System.exit(0) explicitly in order for the program to
finish. You just need to add this to the end of your code.

Sorry if this is all gibberish, its monday morning here. :-)

G.

Diwakar Mantha wrote:

> Hi,
>
> Firstly, thanks for all the answers to my previous questions on this list.
> I have been able to use the transcoder to generate JPEGs from SVG on the fly
> in a webserver, and my boss is quite pleased :-)  Special thanks to Batik
> dev team for a wonderful product.
>
> I observe that some thread (s) do not finish after the transcoding is done.
> Is this a bug?  Or should I be doing some cleanup/setting after transcoding?
> I suspect that this lingering thread (s) is causing my web server to freeze
> up after several transcoding requests.  I instantiate a single
> JPEGTranscoder object to serve all requests, and when a request comes in, I
> simply send in suitable new input and output streams to the transcoder.  The
> first few times (10 or 20), it works fine, after that the images fail to
> download, and then the web server (JRun) freezes up completely.
>
> I have a simple, straightforward Java program below, that converts an SVG
> string to a JPEG file.  When I run it from the command line, it does
> terminate after printing "DONE".  Why?  I have generated a stack trace
> (below), but am not experienced enough to interpret it.
>
> As always, thanks in advance for any suggestions.
>
> --Diwakar
>
> ================== Stack Trace ========================
>
> SIGQUIT
>
> Full thread dump Classic VM (JDK-1.2.2_006, green threads):
>     "Thread-1" (TID:0xebc735e0, sys_thread_t:0x79e358, state:CW) prio=5
>         at java.lang.Object.wait(Native Method)
>         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java, Compiled Code)
>         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java, Compiled Code)
>         at org.apache.batik.ext.awt.image.rendered.TileMap$1.run(TileMap.java,
> Compiled Code)
>     "Thread-0" (TID:0xebc9e808, sys_thread_t:0x5f7150, state:CW) prio=5
>         at java.lang.Object.wait(Native Method)
>         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java, Compiled Code)
>         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java, Compiled Code)
>         at org.apache.batik.util.SoftReferenceCache$1.run(SoftReferenceCache.java,
> Compiled Code)
>     "AWT-Motif" (TID:0xebcc17d8, sys_thread_t:0x4bd258, state:CW) prio=5
>         at sun.awt.motif.MToolkit.run(Native Method)
>         at java.lang.Thread.run(Thread.java, Compiled Code)
>     "SunToolkit.PostEventQueue-0" (TID:0xebcc2288, sys_thread_t:0x49b728,
> state:CW) prio=5
>         at java.lang.Object.wait(Native Method)
>         at java.lang.Object.wait(Object.java, Compiled Code)
>         at sun.awt.PostEventQueue.run(SunToolkit.java, Compiled Code)
>     "AWT-EventQueue-0" (TID:0xebcc2600, sys_thread_t:0x49ad10, state:CW)
> prio=6
>         at java.lang.Object.wait(Native Method)
>         at java.lang.Object.wait(Object.java, Compiled Code)
>         at java.awt.EventQueue.getNextEvent(EventQueue.java, Compiled Code)
>         at
> java.awt.EventDispatchThread.pumpOneEventForComponent(EventDispatchThread.ja
> va, Compiled Code)
>         at
> java.awt.EventDispatchThread.pumpEventsForComponent(EventDispatchThread.java
> , Compiled Code)
>         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java,
> Compiled Code)
>         at java.awt.EventDispatchThread.run(EventDispatchThread.java, Compiled
> Code)
>     "Finalizer" (TID:0xebc98320, sys_thread_t:0x6d060, state:CW) prio=8
>         at java.lang.Object.wait(Native Method)
>         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java, Compiled Code)
>         at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java, Compiled Code)
>         at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:174)
>     "Reference Handler" (TID:0xebc983b0, sys_thread_t:0x68ca0, state:CW)
> prio=10
>         at java.lang.Object.wait(Native Method)
>         at java.lang.Object.wait(Object.java, Compiled Code)
>         at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:114)
>     "Signal dispatcher" (TID:0xebc983e0, sys_thread_t:0x63cf0, state:R)
> prio=5
>     "Thread-2" (TID:0xebcbdaa8, sys_thread_t:0x26dd8, state:CW) prio=5
> Monitor Cache Dump:
>     java.lang.ref.ReferenceQueue$Lock@EBC735D0/EBF4FEB8: <unowned>
>         Waiting to be notified:
>             "Thread-1" (0x79e358)
>     java.lang.ref.ReferenceQueue$Lock@EBC98338/EBCCDD50: <unowned>
>         Waiting to be notified:
>             "Finalizer" (0x6d060)
>     sun.awt.PostEventQueue@EBCC2288/EBDD5AB0: <unowned>
>         Waiting to be notified:
>             "SunToolkit.PostEventQueue-0" (0x49b728)
>     java.awt.EventQueue@EBCC2650/EBDB6468: <unowned>
>         Waiting to be notified:
>             "AWT-EventQueue-0" (0x49ad10)
>     java.lang.ref.Reference$Lock@EBC983C0/EBCCD890: <unowned>
>         Waiting to be notified:
>             "Reference Handler" (0x68ca0)
>     java.lang.ref.ReferenceQueue$Lock@EBC9E7F8/EBDFE898: <unowned>
>         Waiting to be notified:
>             "Thread-0" (0x5f7150)
> Registered Monitor Dump:
>     PCMap lock: <unowned>
>     utf8 hash table: <unowned>
>     JNI pinning lock: <unowned>
>     JNI global reference lock: <unowned>
>     BinClass lock: <unowned>
>     Class linking lock: <unowned>
>     System class loader lock: <unowned>
>     Code rewrite lock: <unowned>
>     Heap lock: <unowned>
>     Monitor cache lock: owner "Signal dispatcher" (0x63cf0) 1 entry
>     Dynamic loading lock: <unowned>
>     Monitor IO lock: <unowned>
>     User signal monitor: <unowned>
>     Child death monitor: <unowned>
>     I/O monitor: <unowned>
>         Waiting to be notified:
>             "AWT-Motif" (0x4bd258)
>     Alarm monitor: <unowned>
>         Waiting to be notified:
>             <unknown thread> (0x2c0c8)
>     Thread queue lock: owner "Signal dispatcher" (0x63cf0) 1 entry
>         Waiting to be notified:
>             "Thread-2" (0x26dd8)
>     Monitor registry: owner "Signal dispatcher" (0x63cf0) 1 entry
>
> ================== Program Output =====================
>
> 1. Creating ImageTranscoder...
> Font specified in font.properties not found [-urw-itc
> zapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecific]
> <More such Font errors deleted here>
> 2. Creating OutputStream...
> 3. Creating InputStream...
> 4. Creating TranscoderInput/Output...
> 5. Transcoding...
> ERROR: The JPEG quality has not been specified. Use the default one: no
> compression
> 6. Closing input and output streams...
> 7. !!! DONE !!!
>
> ================== Program Source =====================
>
> import java.io.*;
> import org.apache.batik.transcoder.TranscoderException;
> import org.apache.batik.transcoder.TranscoderInput;
> import org.apache.batik.transcoder.TranscoderOutput;
> import org.apache.batik.transcoder.image.ImageTranscoder;
> import org.apache.batik.transcoder.image.JPEGTranscoder;
>
> public class th {
>
>  public static void main (String args[]) {
>
>   System.out.println("1. Creating ImageTranscoder...");
>   ImageTranscoder t = new JPEGTranscoder();
>
>   System.out.println("2. Creating OutputStream...");
>   FileOutputStream fos = null;
>   try {
>    fos = new FileOutputStream("jj.jpeg");
>   } catch (FileNotFoundException e) {
>    System.out.println("Error in th: " + e);
>   }
>   OutputStream os = new BufferedOutputStream (fos);
>
>   System.out.println("3. Creating InputStream...");
>   String sv = "<svg width=\"50\" height=\"40\"><rect x=\"0\" y=\"0\"
> width=\"10\" height=\"30\"/></svg>";
>   StringReader is = new StringReader(sv);
>
>   System.out.println("4. Creating TranscoderInput/Output...");
>   TranscoderInput ti = new TranscoderInput(is);
>   TranscoderOutput to = new TranscoderOutput(os);
>
>   System.out.println("5. Transcoding...");
>   try {
>    t.transcode(ti, to);
>   } catch (TranscoderException e) {
>    System.out.println("Error in th: " + e);
>   }
>
>   System.out.println("6. Closing input and output streams...");
>   try {is.close(); os.flush(); os.close();} catch (IOException e)
> {System.out.println("Error in th: " + e); }
>
>   System.out.println("7. !!! DONE !!!");
>  }
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

--

   I don't cause bugs, the surrounding code just fails to adapt quickly enough.
   [EMAIL PROTECTED]

begin:vcard 
n:Davison;Gerard
x-mozilla-html:FALSE
org:Oracle;JDeveloper
adr:;;;;;;
version:2.1
email;internet:[EMAIL PROTECTED]
title:Senior Software Engineer
fn:Gerard Davison
end:vcard

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to