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

  • Home
  • SEARCH
  • 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 6233593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:19:40+00:00 2026-05-24T10:19:40+00:00

public void setGifImage(InputStream inputStream) { checkWidget(); if (thread != null) { thread.stopRunning(); try {

  • 0
public void setGifImage(InputStream inputStream) {
        checkWidget();
        if (thread != null) {
            thread.stopRunning();
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        ImageLoader loader = new ImageLoader();

        try {
            loader.load(inputStream);
        } catch (Exception e) {
            this.image = null;
            return;
        }

        if (loader.data[0] != null){
            System.out.println("set to new picture");
            this.image = new Image(this.getDisplay(), loader.data[0]);
        }

        if (loader.data.length > 1) {
            System.out.println("start animation");
            thread = new GifThread(loader);
            thread.start();
        }else{
            System.out.println("paint static picture");
        }

        redraw();
    }

the thread :

private class GifThread extends Thread {

        private int imageNumber = 0;
        private ImageLoader loader = null;
        private boolean run = true;

        public GifThread(ImageLoader loader) {
            this.loader = loader;
        }

        public void run() {
            while (run) {
                int delayTime = loader.data[imageNumber].delayTime;
                try {
                    Thread.sleep(delayTime * 10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                if (!GifCLabel.this.isDisposed()) {
                    // if a asynchronous thread is running, this new runnable will be queued
                    GifCLabel.this.getDisplay().asyncExec(new Runnable() {
                        public void run() {
                            if (!GifCLabel.this.isDisposed()) {
                                imageNumber = imageNumber == loader.data.length - 1 ? 0 : imageNumber + 1;
                                if (!GifCLabel.this.image.isDisposed())
                                    GifCLabel.this.image.dispose();
                                ImageData nextFrameData = loader.data[imageNumber];
                                System.out.println("set to frame " + imageNumber);
                                GifCLabel.this.image = new Image(GifCLabel.this.getDisplay(), nextFrameData);
                                GifCLabel.this.redraw();
                            } else
                                stopRunning();
                        }
                    });
                } else
                    stopRunning();
            }
        }

        public void stopRunning() {
            run = false;
        }
    }

the output :

2011-08-10 03:44:24 DEBUG  - 日志服务Ready!
2011-08-10 03:44:28 DEBUG  - current is null
2011-08-10 03:44:28 DEBUG  - found : amarsoft.dbmp.function.ui.FunctionListPage@1079ff
2011-08-10 03:44:28 DEBUG  - can go back ? false
2011-08-10 03:44:28 DEBUG  - can go forward ? false
set to new picture
start animation
2011-08-10 03:44:28 DEBUG  - 尝试连接至 - jdbc:mysql://localhost:3306/credit 驱动配置:MySQL 驱动类:com.mysql.jdbc.Driver@1f7abae 连接属性:{user=root, password=root}
set to frame 1
set to frame 2
set to frame 3
set to frame 4
[amarsoft.dbmp.function.ui.FunctionListPage$1@29f93b, amarsoft.dbmp.function.ui.FunctionView$1@1a998c7]
set to new picture
paint static picture
set to frame 5

I wonder why the thread still run after thread.join()? As I know, thread.join() wait thread to die,but you can see the last line in output, thread run after die…

  • 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-24T10:19:42+00:00Added an answer on May 24, 2026 at 10:19 am

    The issue here is that you thread calls getDisplay().asyncExec() which basically sends event to UI thread to execute the Runnable that prints "set to frame ".

    Better to use syncExec() and check run variable status inside Runnable too.

    Another hints:

    1. it’s not a good idea to catch InterruptedException and do nothing.
    2. call interrupt inside stopRunnable()
    3. check run variable status after sleep ends.

    Cheers,
    Max

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

Sidebar

Related Questions

public void foo() { begin(); try { ... commit(); } catch (Exception e) {
public void EatDinner(string appetizer, string mainCourse, string dessert) { try { // Code }
public void Add(IDataProvider provider){ var key=KeyValue(); if(key==null){ var newKey=_repo.Add(this,provider); this.SetKeyValue(newKey); }else{ _repo.Add(this,provider); //NullReferenceException was
public void item_bound(object sender,DataGridItemEventArgs e) { try { if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType ==
//node.h class node { public: void sort(node n); }; I didn't try the code
public void LoadAveragePingTime() { try { PingReply pingReply = pingClass.Send(logon.chronic-domination.com); double AveragePing = (pingReply.RoundtripTime
public void LoadRealmlist() { try { File.Delete(Properties.Settings.Default.WoWFolderLocation + Data/realmlist.wtf); StreamWriter TheWriter = new StreamWriter(Properties.Settings.Default.WoWFolderLocation
public void stop(){ setRun(false); inComingWorkThread.interrupt(); outGoingWorkThread.interrupt(); } I was trying to stop those thread
public void aMethod(){ new Thread(new Runnable() { public void run() { int decide =
public void testFinally(){ System.out.println(setOne().toString()); } protected StringBuilder setOne(){ StringBuilder builder=new StringBuilder(); try{ builder.append(Cool); return

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.