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 1084875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:37:04+00:00 2026-05-16T22:37:04+00:00

I have a class MyModel with a property datalogEnabled (and other ones, but let’s

  • 0

I have a class MyModel with a property datalogEnabled (and other ones, but let’s start there) that I would like to be able to implement properly for use with UI/view binding.

public class MyModel  { 
    static final String KEY_DATALOG_ENABLED = "datalogEnabled";
    final private PropertyChangeSupport pcs = new PropertyChangeSupport(this); 
    final private Object syncLock = new Object();   
    final private Datalogger datalogger = new Datalogger();

    public void addPropertyChangeListener(PropertyChangeListener pcl)
    {
        this.pcs.addPropertyChangeListener(pcl);
    }
    public void removePropertyChangeListener(PropertyChangeListener pcl)
    {
        this.pcs.removePropertyChangeListener(pcl);
    }    
    public boolean isDatalogEnabled() 
    {
        synchronized (this.syncLock) 
        {
            return this.datalogEnabled; 
        }
    }
    public void setDatalogEnabled(final boolean enable) {
        boolean old;
        synchronized (this.syncLock) {
            old = this.datalogEnabled;
            this.datalogEnabled=enable;             
        }
            /* begin snippet X: this is wrong for threading reasons */
        this.pcs.firePropertyChange(KEY_DATALOG_ENABLED, old, enable);      
            setDatalogEnabledNow(enable);
            /* end snippet X */
    }   
    setDatalogEnabledNow(boolean b)
    {
        this.datalogger.setEnable(b);
    }
    /* other methods */
}

public class Datalogger() { 
    public void setEnable(boolean enable) { ... }
}

Except for snippet X, this seems right, but I’m not sure. What’s getting me is that the various ways of accessing/setting/listening to the property may happen on different threads, and what I need to do is to act upon the datalogEnabled property somewhere (do some file I/O) within my Datalogger class, on another thread besides the Swing UI thread, because I don’t want the UI thread to be unresponsive.

How can I properly rewrite snippet X?

In my overall program, I have an instance of ExecutorService. I could add an Executor (superclass of ExecutorService) as a constructor parameter in the MyModel class, and do this for snippet X:

this.pcs.firePropertyChange(KEY_DATALOG_ENABLED, old, enable);      
this.executor.execute(new Runnable() {
     @Override public void run() { setDatalogEnabledNow(enable); }
});

Should I put the firePropertyChange call into the deferred Runnable task as well? (is firePropertyChange supposed to be called immediately or after a property change really takes effect)

Or should the Datalogger class have an Executor as well so it can coordinate various tasks?

I’m confused on this one….

  • 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-16T22:37:04+00:00Added an answer on May 16, 2026 at 10:37 pm

    The listeners of a model can be uis components, or domains components. If a listener is a ui component, it must run on the edt, and not if the listener is domain.

    The event come from a ui component, or from a domain component. If the event come from a ui component, the fire method is on the edt, and it is not if the event come from a domain.

    So it’s a little complicated… My opinion is than each listener should work for itself : a ui listener goes on the edt if it is not, and a domain goes not if it is. So the fire method stays on it’s original thread.

    2 cts.

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

Sidebar

Related Questions

I have a model: class MyModel(models.Model): id = models.IntegerField(primary_key=True) recorded_on = models.DateField() precipitation =
I have a model similar to this: public class myModel { public ClassA ObjectA
I have a model with a datetime field: class MyModel(models.Model): created = models.DateTimeField(auto_now =
I have a standard ActiveRecord model with the following: class MyModel < ActiveRecord::Base custom_method
in a Model I have a CharField with choices: class MyModel(models.Model): THE_CHOICES=( ('val',_(u'Value Description')),
I have a class thats created as a resource: <Window.Resources> <Model:MyModel x:Key=model /> </Window.Resources>
I have a couple model classes like so: public class MyModelBase { public string
In my model I have class Alias include DataMapper::Resource belongs_to :user property :id, String,
If I have in my model class a property of type DateTime how can
I have a simple Model: public class MyModel { public string Text{get;set;} } I

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.