Swing isn't thread safe, what about AWT?

Since Swing isn't really thread safe what does that mean for AWT? Is AWT thread safe? Also if it is doesn't that mean one should use AWT over Swing since AWT is thread safe?

Trizi wrote:
jverd wrote:
Trizi wrote:
[http://forum.java.sun.com/thread.jspa?threadID=5282846&tstart=0|http://forum.java.sun.com/thread.jspa?threadID=5282846&tstart=0]
There ya go duffy the hom^oYou say that is if being gay were a bad thing. So, besides being an obnoxious fuckhead, you're also a homophobic troglodyte? Man your fiancee must be a real winner to have picked you. My guess is that she's either a sheep, a blow-up doll, or someone you've got bound and gagged in your basement.Now from what everyone is saying that I don't have anything original...
You don't either, too much "Silence of the Lambs" maybe?Dude, try speaking English.
By the way, I am sure if I was a troglodyte I would be in a museum, also I have homosexual friends, sorry not homophobic, I just found a good ting to his name and figured I'd exploit it.. Just like I'm exploiting your pathetic intelligence.You really need help if you think the above makes any sense or any point.

Similar Messages

  • What does, "swing is not thread safe." mean?

    can anyone explain what that means in detail?

    [Google can|http://letmegooglethatforyou.com/?q=swing+is+not+thread+safe+tutorial]
    For better response, you may wish to ask a specific question that's answerable without having to write a book chapter.

  • SwingWorker process(List V chunks) but List isn't thread safe is it.

    Folks,
    Am I missing something or does
    protected void process(List<V> chunks)in the new 1.6 javax.swing.SwingWorker represent a potential threading issue?
    List isn't thread safe... so why not use a Vector, which is? Except that Vector is currently considered persona-non-grata by bigger brains than me.
    Hmmm... Of course, I don't know which implementation of List is being used under the hood, so I suppose I just have to trust the Java Gods who built the new SwingWorker to have used a thread safe implementation... which is pretty good bet, I suppose...
    Can anyone state categorically that it isn't a problem?
    Thanx. Keith.
    Message was edited by: corlettk PS: I'm knee deep in thread gruel and going down fast.

    publish definitely does not block until process is finished.
    In fact calling publish does not necessarily mean that process will be called right away.
    From the API:
    Because the process method is invoked asynchronously on the Event Dispatch Thread multiple invocations to the publish method might occur before the process method is executed. For performance purposes all these invocations are coalesced into one invocation with concatenated arguments.
    For example:
    publish("1");
    publish("2", "3");
    publish("4", "5", "6");
    might result in:
    process("1", "2", "3", "4", "5", "6")
    Edit:
    The only source I could find for AccumulativeRunnable (the class used to accumulate the arguments passed to publish) was here:
    http://fisheye5.cenqua.com/browse/swingworker/src/java/org/jdesktop/swingworker/AccumulativeRunnable.java?r=1.2
    which isn't necessarily the implementation in the JDK but it's probably close.
    That shows that before process is called the accumulating list reference is nulled, meaning that there is no way that publish can append to the list during a call to process.
    In fact calling publish as the same time as process is executing on the EDT appends the published arguments to a fresh list, leading to another call to process at some later time (in SwingWorker the delay between a call to publish and a call to process is at most 1000/30 milliseconds).
    Message was edited by:
    dwg

  • Thread safe - what's that mean?

    Hello,
    I'm new to Java technology and I constantly read the Java forum as one way to learn from other's experience. What's that mean by "thread safe" as I often saw it in the forum and what's the difference between "thread" and "process"?
    Thanks in advance.
    wg97

    I'm new to Java technology and I constantly read the
    Java forum as one way to learn from other's
    experience. What's that mean by "thread safe" as I
    often saw it in the forum and what's the difference
    between "thread" and "process"?I'll answer the second question first. The difference between thread and process depends on context. Generally in Java programming threads are well defined and processes are more general. A thread is a set of executing instructions in the VM that can execute "concurrently" with other sets of executing instructions. An appliction always contains at least one thread often called the 'main' thread. The main thread can spawn other threads so an application can have multiple concurrent sets of executing instructions. Thread-safe methods are those that enforce rules about how objects can access them i.e. they make sure that two threads are not performing actions on a single object at the same time that can result in errors. This is done in Java using the synchronized keyword.

  • Is TelemetryClient thread-safe?

    The only tutorial for client events I found is down at the moment (404):
    http://azure.microsoft.com/en-us/documentation/articles/app-insights-web-track-usage-custom-events-metrics
    However looking at the cached version, it doesn't mention threading concerns.
    The docs say its methods are not thread safe but I'm wondering if that's just the boilerplate template. If it really isn't thread safe, what
    is the recommended practice in a multi-threaded environment? lock around each call? instantiate a new client for each call? synchronize calls in a queue?
    Thanks,
    Ohad

    Hi Oleg, thanks for clarifying that.
    Perhaps you could modify the docs to point that out.
    I'm confused though, why pay the overhead of thread-safety if you recommend creating a new instance every time?
    BTW I don't know if it was your doing, but the
    article is back online :)

  • What does it mean to be "thread safe"?

    What does it mean to be "thread safe"?
    I am working with a team on a project here at work. Someone here suggested that we build all of our screens during the initialization of the application to save time later. During the use of the application, the screens would then be made visible or invisible.
    One of the objections to that idea was that the swing components (many of which we use) are not thread safe. Can anyone tell me what the relevance of that is?
    Thanks

    To understand why Swing is not thread safe you have to understand a little bit of history, and a little bit of how swing actually works. The history(short version) is that it is nearly impossible to make a GUI toolkit thread safe. X is thread safe(well, sorta) and it's a really big mess. So to keep things simple(and fast) Swing was developed with an event model. The swing components themselves are not thread safe, but if you always change them with an event on the event queue, you will never have a problem. Basically, there is a Thread always running with any GUI program. It's called the awt event handler. When ever an event happens, it goes on an event queue and the event handler picks them off one by one and tells the correct components about it. If you have code that you want to manipulate swing components, and you are not ON the awt thread(inside a listener trail) you must use this code.
    SwingUtilities.invokeLater( new Runnable() {
      public void run() {
        // code to manipulate swing component here
    });This method puts the defined runnable object on the event queue for the awt thread to deal with. This way changes to the components happen in order, in a thread safe way.

  • What is "Thread Safe"?

    I have heard a lot of folks talking about a class that is "Thread Safe".
    I am assuming that this means the obect can be accessed by more than one thread at a time. I do not know what the concept really means in practice.
    My question is, how can I tell if something is thread safe, what do I need to look out for?

    Basically you're looking to avoid unwanted behavior by simultaneous access. Here are a couple examples I've seen:
    Assuming myID is a class variable...
    public void assignID(Client currentClient) {
    myID = (some new random value)
    currentClient.ID = myID;
    In the above example, what happens if two threads access the method at the same time? The first one starts, assigning a value to the myID variable. Then the second one starts, assigning a value to myID AGAIN. Then when both clients assign their currentClients, they'll both end up with the same ID. To avoid a code block being accessed by two clients simultaneously, use the "synchronized" keyword.
    Here's another one. Assume you have a Hashtable:
    Enumerator myEnum = myHashtable.keys()
    while (myEnum.hasMoreElements()) {
    Object myKey = myEnum.nextElement();
    myHashtable.remove(myKey);
    This should not work in Java (and I know it doesn't in C# which I'm currrently being forced to use at work) because you're iterating through the keys of a Hashtable. But while you're trying to go linearly from key to key, you're also removing elements of the Hashtable. You're trying to operate on the object twice and the object doesn't allow it.
    There are a couple ideas. I wrote a database pool once and had to synchronize methods so two clients didn't try to execute a query through the same Connection, etc.
    Michael Bishop

  • Swing thread safe ?

    Hi
    Are swing comonents are thread safe ?
    If i am not wrong the thread safe objects are those whose data changes are predictable ( i mean no race condition)
    Is this correct ?
    I had worked on multithreaded application in MFC where we used Message queues for hadling the multithreading
    Can i use the same logic in java also ? If yes can anybody help me how can i do it
    Thanks in advance

    The Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html]Using Threads explains the concept of "Thread Safe".

  • Are static nested classes thread-safe?

    There doesn't seem to be any definitive answer to this. Given the following code, is it thread-safe?
    public class SomeMultiThreadedWebController {
    public HttpServletResponse someMethodToExecuteViaWebRequest(HttpServletRequest request) {
        simpleQueryBuilder("SELECT...").addParameter("asdf","asdf").createQuery(EMF.getEntityManager()).executeUpdate();
    protected static class SimpleQueryBuilder {
             private String queryString;
             private Map<String, Object> params = new HashMap<String, Object>();
             public SimpleQueryBuilder(String queryString) {
                  this.queryString = queryString;
             public SimpleQueryBuilder addParameter(String name, Object value) {
                  params.put(name, value);
                  return this;
             public Query createQuery(EntityManager em) {
                  Query query = em.createQuery(queryString);
                  for (Entry<String, Object> entry : params.entrySet()) {
                       query.setParameter(entry.getKey(), entry.getValue());
                  return query;
        public static SimpleQueryBuilder simpleQueryBuilder(String queryString) {
             return new SimpleQueryBuilder(queryString);
    }Forget whether or not someone would do this, as this is just an example. I'm really trying to get at whether or not the instance variables inside the static nested class are thread-safe. Thanks for any responses.

    Hello,
    I believe you understand what you're talking about, but you state it in a way that is very confusing for others.
    Let me correct this (essentially, incorrect uses of the terminology):
    I agree that thread-safe or not is for an operation, for a member, it has some sort of contextual confusion.
    Member has a much broader meaning in the [Java Language Specification|http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.4] . Even "class member" applies to both an attribute, a method, or an inner class or interface.
    I think you mean "member variable" of a class (aka "attribute" or "field"). By the way, static or not is irrelevant to the rest of the discussion.
    For an operation or a member, if there's only one thread could access it atomically in one moment, we could call it thread-safe.Mmm. I was tempted to say yes (I'm reluctant to commit myself). With an emphasis on "_The encapsulating class_ makes this member's usage thread-safe".
    Still, just synchronizing each operation on a member is not enough to make all usages "thread-safe":
    Consider a java.util.Vector: each add/get is synchronized, so it is atomic, fine.
    However if one thread adds several values, let's say 3, one by one, to a vector that initially contains 0 values, and another thread reads the vector's size() (another properly synchronized method), the reader thread may witness a size anywhere among 0, 1, 2, 3, which, depending on the business logic, may be a severely inconsistent state.
    The client code would have to make extra work (e.g. synchronizing on the vector's reference before the 3 adds) to guarantee that the usage is thread-safe.
    Thus any synchronized method(With the limit stated above)
    or immutable member (like primitive type) are thread-safe.
    Additionally for a member, if it's immutable, then it's thread-safe. You mean, immutable primitive type, or immutable object. As stated previously, an immutable reference to a mutable object isn't thread-safe.
    a static final HashMap still have thread-safe issue in practice because it's not a primitive.The underlined part is incorrect. A primitive may have thread-safety issues (unless it's immutable), and an object may not have such issues, depending on a number of factors.
    The put, get methods, which will be invoked probably, are not thread-safe although the reference to map is.Yes. And even if the put/get methods were synchronized, the client code could see consistency issues in a concurrent scenario, as demonstrated above.
    Additional considerations:
    1) read/write of primitive types are not necessarily atomic: section [ §17.7 of the JLS|http://java.sun.com/docs/books/jls/third_edition/html/memory.html#17.7] explicitly states that writing a long or double value (2 32-bits words) may not be atomic, and may be subject to consistency issues in a concurrent scenario.
    2) The Java Memory Model explicitly allows non-synchronized operations on non-volatile fields to be implemented in a "thread-unsafe" way by the JVM. Leading way to a lot of unintuitive problems such as the "Double-Checked Locking idiom is broken". Don't make clever guess on code execution path unless you properly synchronize access to variables across threads.
    Edited by: jduprez on Mar 4, 2010 9:53 AM

  • Is KeyStore thread safe?

    Hi all,
    My class has KeyStore instance as static field.
    When KeyStore#getKey(String alias, char[] password) mthod is called with right alias and password on multi-thread environment, normaly I can get Key object successfully.
    But rarely following UnrecoverableKeyException is thrown from that method.
    Caused by: java.security.UnrecoverableKeyException: Given final block not properly padded
         at com.sun.crypto.provider.SunJCE_z.a(DashoA13*..)
         at com.sun.crypto.provider.JceKeyStore.engineGetKey(DashoA13*..)
         at java.security.KeyStore.getKey(KeyStore.java:763)Is KeyStore (specifically JceKeyStore) thread safe?
    Thanks in advance.

    In general a Java API class or method isn't thread safe unless it is specifically so documented.
    You could always synchronize it and see if it helps ...

  • Is java.xml.parsers.DocumentBuilder Thread Safe?

    Does anyone know if the DocumentBuilder is thread safe? Meaning,
    can I call the parse(...) methods from several threads simultanously, without getting errors?
    I would be happy if anyone can also point me to the documentation that says DocumentBuilder is or isn't thread safe.

    My Code Like Such:
    public class DigestUtil
    private static MessageDigest md_md5 = null;
    static
    try{
    md_md5 = MessageDigest.getInstance("MD5");
    }catch(Exception ex)
    public static byte[] DigestMD5(byte[] b)
    return b==null ? null : md_md5.digest(b);
    I Don't Wish to Every Digest, Every Create MessageDigest Instance.

  • Please confirm that stubs are thread-safe

    Can someone please confirm that if one is to invoke the same remote method from more than one thread in a client application that one does not need to get multiple remote stubs for the same RMI server object. As long as the implementation of the remote method is thread safe, everything okay, correct?
    In otherwords, are remote stubs them selves thread safe? I always assumed they were.
    Thanks in advance

    Stubs are threadsafe. The reason is that a second concurrent invocation via the same stub will use a new TCP connection. I took this up with Sun once and the response was along the lines 'if it doesn't say it isn't thread-safe, it's thread-safe'.
    It's the method implementation at the server that isn't thread-safe, unless you make it so.

  • SingleThreadModel-static variables thread safe?

    Hi..
    I have one servlet which implements SingleThreadModel.My servlet contains two static variables .
    public class MyServlet extends HttpServlet
    implements SingleThreadModel {
    private static String firstName="Umar hathab";
    private static StringBuffer lastName= new StringBuffer("Abdullah");
    I want to know whether this two variables will be thread safe? I know that static vars are shared in JVM..
    Please help me..
    Thanks in advance..
    A.Umar

    Hi heyad..
    Static variables are shared among the instances.When we create two instances of an object which contains a static variable,both the instances share the same static variable.So there will be data corruption when two instances operate on the static variable at the same time.So I feel static variables are not thread safe.What I want to know is whether static variables are thread-safe when implemented by SingleThreadModel..
    A.Umar

  • Trying to understand "thread-safe" w/ swing components

    The other day there was a big hullabaloo about some code I posted because I was calling JLabel.setText from a thread that wasn't the ui thread. On the other hand, this thread was the only thread making changes to the JLabel. My understanding is that in any kind of multi-threaded system, if you just have 1 writer / changer, then no matter how many readers there are, this is thread-safe. So why what I was doing not thread safe?
    Second question - JLabel.setText() is essentially setting data in the model for JLabel, which then gets picked up and displayed the next time the GUI thread paints it. So if it's not safe to update a JLabel's model, I assume its never safe to update any data that also is being displayed visually. So for instance, if I was showing some database table data in a JTable, I should do the update in the UI thread - probably not. But what is the distinction?
    Third question - what swing components and what operations need to be run on the UI thread to call your program "thread-safe". Validate? setSize()? setLocation()? add? remove? Is there anything that can be called on swing components from a non-ui thread?
    Edited by: tjacobs01 on Nov 2, 2008 8:29 PM

    tjacobs01 wrote:
    My understanding is that in any kind of multi-threaded system, if you just have 1 writer / changer, then no matter how many readers there are, this is thread-safe. So why what I was doing not thread safe?This is not true. As I mentioned in that hullabaloo thread, the Java Memory Model allows threads to cache values of variables they use. This means that values written by one thread are not guaranteed to ever be visible to other threads, unless you use proper synchronization.
    Take the following example:
    import java.util.concurrent.TimeUnit;
    public class ThreadExample {
        static class Foo {
            private String value = "A";
            public String getValue() {
                return value;
            public void setValue(String value) {
                this.value = value;
        public static void main(String[] args) {
            final Foo foo = new Foo();
            Thread writer = new Thread() {
                @Override
                public void run() {
                    try {
                        TimeUnit.SECONDS.sleep(1);
                        foo.setValue("B");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
            Thread reader = new Thread() {
                @Override
                public void run() {
                    try {
                        TimeUnit.MINUTES.sleep(1);
                        System.out.println(foo.getValue());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
            writer.start();
            reader.start();
    }Here two different threads both access the same Foo instance, which is initialized with a value of "A". One thread, the writer, sleeps one second, and then sets foo's value to "B". The other thread, the reader, sleeps one minute (to avoid race conditions) and then prints foo's value to System.out. It may seem obvious that the reader thread will read the value "B", but this is in fact not guaranteed to be true. The reader thread may never see the value that was written by the writer thread, so it may very well read the old value "A".
    (If you run the code you will probably see "B" printed out, but again, this is not guaranteed behavior.)
    A simple way to fix this is to synchronize access to the mutable state that the two threads share. For example, change the class Foo to
        static class Foo {
            private String value = "A";
            public synchronized String getValue() {
                return value;
            public synchronized void setValue(String value) {
                this.value = value;
        }It's for this same reason that you often see the use of a volatile boolean as a control flag for stopping threads, rather than a plain old boolean. The use of volatile guarantees that the thread you want to stop actually sees the new value of the flag once it has been set by another thread.
    Here is an article that touches some of this stuff:
    [http://www.ibm.com/developerworks/java/library/j-jtp02244.html]
    I also highly recommend the book "Java Concurrency in Practice" (one of the authors of which, David Holmes, sometime hangs out on the Concurrency forum here, I believe).
    Edited by: Torgil on Nov 2, 2008 9:01 PM

  • Confused about static thread safe.help me

    sample codes look like follows:
    public static class test
          public static method1(Object obj)
                //some operations  
    }my question is that is method1 is thread safe?

    Thread safety isn't about methods and it isn't about static. It's about being carefully about access to resources which may be accessed by more than one thread, and in particular may be changed by one thread and accessed by another.
    Local variables are always thread safe, and there's no problem about serveral threads executing the same block of code concurently.
    Thread safety is, in particular, about data items that are linked in some way so that there can be problems if one thread updates one piece of data on the basis of an out of date version of another.
    Databases are, generally, designed to cope with that kind of thing.

Maybe you are looking for

  • Deleting songs from itunes Library and syncing

    I have loaded up my nano with most of my personal cd's and some purchased songs. I'd like to delete most of the songs off of the itunes library (sorta seems like double kill since they are on my nano and computer)...I really only need them in one spo

  • Ctrl+Right Click not working

    Hi all, I am using EP version 6.4 and ESS/MSS 100 SP 22. Backend system is ECC 5.0 and SAP-HR/EA-HR SP75. I am unable to do end user personalization in the portal iviews. Ctrl+Right Click is not working. Any idea whether this works on this version or

  • XSLT file with process_data values

    Hi there, I have a process that takes in an XML file and some XSLT in another document variable and some process_data values from the main process. Inside this process I would like to invoke the XSLT on the XML and use the process_data values inside

  • Feasibility of making a RAC installation on a single machine

    Hii, Is it possible to make a RAC installation on a single machine using oracle 11gR2?If so, how?Pls guide me through.

  • Using Spry Navigation with php includes in a Dreamweaver dwt file

    I am working on a large site and am attempting to set up templates in Dreamweaver, which will include the navigation as an includes file with php.  First of all, wondering if it is possible?  Second, how do I address the problem of my pages being at