Question: I have a simple button, and I want to use CSS to make it onhover, bring up a dropdown of a few more buttons with links, and when the button is pressed I want the button to stay at the onhover state. How can this be accomplished? For example a games button that when hovered over it drops down to buttons that have different links to games. Sorry if this is unclear. Thanks in advanced.

Answer: 
> 
> I figured the class could not be made thread-safe since even if you synchronize both methods, you could have a situation that Thread1 would invoke the setter and before Thread1 could invoke the getter, Thread2 might execute and invoke the setter, so that when Thread1 went and retrieved the result it would get the wrong info. Is this the right way to look at things?
> 
> 
> 

You are correct with this. There is no way to guarantee that a thread will not have called either of the methods in between your calls of each of the methods, **from within the class**.

If you do want to do this, that will require a wrapper class.
So if the class with the getter and setter is like so:

```
class Foo
{
    private static int bar;

    public static synchronized void SetBar(int z) { ... }
    public static synchronized int GetBar() { ... }
}

```

The wrapper class would look something like this:

```
class FooWrapper
{

    public synchronized int SetGetBar(int z)
    {
        Foo.SetBar(z);
        return Foo.GetBar();
    }

}

```

The only way to guarantee this will work is if you can guarantee that all calls will go through your wrapper class rather than directly to class Foo.
`synchronized` in Java is an object-wide lock. Only one `synchronized` method of any given object can be executed on any given thread at a time. Let's have this class:

```
class Foo
{
    private int bar;

    public synchronized void SetBar() { ... }
    public synchronized int GetBar() { ... }
}

```

* Thread 1 calls `SetBar()`. Thread 1 acquires the object lock.
* Thread 2 wants to call `SetBar()`, but Thread 1 holds the lock. Thread 2 is now queued to acquire the lock when Thread 1 will release it.
* Thread 1 finishes executing `SetBar()` and releases the lock.
* Thread 2 immediately acquires the lock and starts executing `SetBar()`.
* Thread 1 calls `GetBar()`. Thread 1 is now queued to acquire the lock when Thread 2 will release it.
* Thread 2 finishes executing `SetBar()` and releases the lock.
* Thread 1 acquires the lock, executes `GetBar()`, and is done with it.

You did the work twice, but you didn't cause any race condition. It may or may not be erroneous to do the work twice, depending on what it is.

A frequent pattern is to have one thread produce content and one other thread do something useful with it. This is called the producer-consumer pattern. In this case, there is no confusion over who or what tries to `SetBar()` and what tries to `GetBar()`.