Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 867131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:55:32+00:00 2026-05-15T09:55:32+00:00

I wrote an application that uses GraphViz to generate some graphs as .gif’s according

  • 0

I wrote an application that uses GraphViz to generate some graphs as .gif’s according to the DOT syntax. When I run from Eclipse the images are generated fine but when I export it as a jar the images are created but there is no data in them. When I view them in Microsoft Picture Viewer its just the red X.

It was working as an exported jar until I put the picture generation in its own thread. I can’t seem to figure out whats going on here. Are there any problems exporting multi-threaded projects? Any one have any ideas?

Thanks

Here is some of the code. Its hard to pin point what is going wrong.

/**
* Writes the graph's image in a file.
* @param img   A byte array containing the image of the graph.
* @param to    A File object to where we want to write.
* @return Success: 1, Failure: -1
*/

public int writeGraphToFile(byte[] img, File to)
   {
      try {
         FileOutputStream fos = new FileOutputStream(to);
         fos.write(img);
         fos.close();
      } catch (java.io.IOException ioe) { return -1; }
      return 1;
   }

The above function is called from an alternate thread by this call.

public void generateMainGraph() {
        //create the graph and put it to file name mainGraphCount.gif
        GraphViz gv = new GraphViz();
        System.out.println("Generating MAIN graph...");

        //add the ending } to mainDot
        mainDot += "}";

        File newGraph = new File("graphs\\main" + Integer.toString(mainGraphCount) + ".gif");
        gv.writeGraphToFile(gv.getGraph(mainDot), newGraph);
}

Here is the thread that calls the function which makes the call to generateMainGraph(…).

graphGeneratingThread = new Runnable() {
            //This method will run in the timer thread
            public void run() {
                try {
                    //Generate the graphs
                    if (iData.importDataSet()) {
                        int timeout = 0;
                        Scanner scan = new Scanner(graphGen.logSource);
                        while(timeout < 10) {
                            if(!scan.hasNextLine()) {
                                Thread.sleep(1000);
                                timeout++;
                            } else {
                                timeout = 0;
                                graphGen.generateGraph(scan.nextLine());   //This function calls generateMainGraph(...)
                                if(!beginningButton.isEnabled()) {
                                    enableTivoButtons();
                                }
                            }
                        }
                    }
                } catch(Exception exc) {
                    System.err.println("GraphGenerationThread Runnable Error: " + exc.getMessage() + "\n");
                    exc.printStackTrace();
                    System.exit(1);
                }
            }
        };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T09:55:32+00:00Added an answer on May 15, 2026 at 9:55 am

    It does not make a difference if a project is multithreaded or not when you export it. Differences are cause by how the threads are being scheduled by the VM (which may be effected by running inside of eclipse).

    Since your problem is with the threaded version my guess is you have internal object state that is being corrupted in the middle of the operation of one thread by another thread. For example:

    1. Thread A generates the image data
    2. Thread B replaces the data array with an empty one
    3. Thread A writes data (which is now empty from step 2)

    this would be an explanation for a 0 byte image. Another scenario:

    1. Thread A starts generating image data
    2. Thread B starts generating image data
    3. Thread A completes generating data.
    4. Thread A writes image data (which now contains part of thread B’s data)

    This would be a cause of a corrupt image file. Debugging concurrent code can be tricky. My suggestion is:

    1. Find any code that can be invoked by more than thread at once.
    2. Add logging statements including Thread.currentThread().getName() if it is not already part of a logging API you are using.
    3. Look at the interleaving of the two threads this should give you ideas of where data may becoming corrupt.

    If you are looking for a “simple solution” after you find code that can be run by more than thread at once and effect your data simply make that method synchronized, however that will likely defeat what you are trying to achieve in adding the Threads.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote an application using wxWidgets that uses wxList . I am having some
I added a table to a database that my application uses and wrote some
I wrote a complex Java application with eclipse that uses many .jar libraries included
I have an application that we wrote here at work that uses the SharpSVN
I wrote a Java application that reads and sends SMS messages from a USB
I wrote an application that uses sqlite and it works great on most of
I have an application that uses images from web a a source. for my
I wrote a quick console application that uses SharePoint dll files. If I attempt
I wrote an unit-test using MSTest for my Application which uses functionality from a
I wrote a Java application that uses the java.awt.Robot to take screen captures of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.