bitguru blog

a guru of bits, or just a bit player?

Archive for March, 2007

Tampa Casino Tour

Posted by bitguru on March 28, 2007

I don’t know if you have ever tried to use internet search engines to discover if there are poker rooms in a city you are about to visit, but the results when I try it are always disappointing. The promising links appear to be casino listings, but are actually spamdexes (spamdices?).

So as a public service I thought I’d list three Tampa card rooms I managed to track down: Read the rest of this entry »

Advertisements

Posted in Poker | 1 Comment »

Will the real Swing Single Threading Rule please stand up?

Posted by bitguru on March 21, 2007

disclaimer: This entry isn’t intended for a general audience. If you’re not a Swing programmer, you’ll probably want to skip it.

This is what a Swing “hello world” program used to look like.

import javax.swing.*;

public class HelloWorld2002 {

	public static void main(String[] argv) {
		JLabel bulletin = new JLabel("Hello, world!", JLabel.CENTER);

		JFrame frame = new JFrame("Bulletin");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(bulletin); // adds to CENTER
		frame.setSize(200, 150);
		frame.setVisible(true);
	}
}

This is pretty much the same as the code on page 85 of my book. In fact, just about all the examples in the book kick things off this way. They create JFrames and other JComponents in the main thread, either directly in main() or indirectly. Swing is not thread-safe (by design) so we have always had to be careful. For example, if we want to call bulletin.setForeground(Color.RED) after the frame is visible, we have to make sure it executes in the event-dispatching thread. If it executes in the main thread or some other thread it’s likely to work just fine, but there are no guarantees and it is possible that bad things (such as deadlock) may happen. Even if it seems to work on your development machine, it may fail intermittently, or it may even deterministically fail on some platform on which you haven’t tested or on some future release of the JDK.

Swing Single Threading Rule (through 2003)
Once a Swing component has been realized*, only the event-dispatching thread should affect or query the component.
*Realized means that the component has been painted onscreen, or is ready to be painted. The methods setVisible(true) and pack cause a window to be realized, which in turn causes the components it contains to be realized.

Several years ago I heard rumors that intermittent errors on the Solaris operating system could be worked-around by doing everything on the event-dispatching thread. By everything I mean not only the manipulation of realized components, but also of unrealized ones, and even the instantiation of the components themselves.

I never heard anything official in this regard, but it often pays to be cautious so I started doing this in most of my production code. I noticed that other Swing programmers started doing it in their code too.

Flash forward to last week. I was at a job interview. I had submitted a code sample that set up the GUI in the main thread, and now I was being asked about it. As a Swing expert, how could I have made such a common error?
Read the rest of this entry »

Posted in Java, Swing | 13 Comments »

I’m not Kisslish

Posted by bitguru on March 11, 2007

My four-year old son often claims, “I’m not ticklish.” But when he was receiving some kissing this afternoon, possibly against his will, he declared, “I’m not kisslish.” Cute, eh? He’s been impressing me with his vocabulary lately, and not only with made-up (if apt) words.

I’m unsure of spelling the of kisslish. He clearly pronounced it with three syllables, so I almost went with kisselish or kissleish. But ticklish is usually pronounced with three syllables in my experience, though my dictionary does not concur.

As an aside, what’s the deal with commas before quotation marks? I reluctantly included them here because they have been deemed correct, but I don’t like it. I don’t use them when composing email and other informal communications. I’m not sure why I don’t put blog entries in that category.

Posted in Kids | 4 Comments »

Lottery Denouement

Posted by bitguru on March 8, 2007

The jackpot prize pool for Tuesday’s Mega Millions lottery drawing turned out to be $233 million, corresponding to an advertised jackpot of $390 million. The unclaimed jackpot prize pool for the March 2nd drawing was approximately $164.3 million.

The jackpot prize pool is 31.8% of sales so, at a doller per a ticket, 216 million tickets must have been sold for the March 6th drawing to account for the $68.7 million difference. That’s a lot of tickets. Presuming that the numbers on those tickets were chosen uniformly, we’d expect 1.23 of those 216 million tickets to exactly match your ticket. Even if your crazy time-travelling uncle told you the winning numbers in advance, you would expect to be splitting the jackpot two or three ways.

Read the rest of this entry »

Posted in Lottery | 1 Comment »

$400 million Lottery Jackpot

Posted by bitguru on March 6, 2007

The estimated jackpot for tonight’s Mega Millions state lottery (California, Georgia, Illinois, Maryland, Massachusetts, Michigan, New Jersey, New York, Ohio, Texas, Virginia, and Washington) drawing is up to almost $400 million.

The lottery has deservedly been called a stupidity tax, but how does this record jackpot change things? The odds of any specific ticket winning are 175.7 million to one. That gives a naive expected value of about $2.25 for each $1 ticket. Not bad, eh? Why not take out a short-term $175.7 million loan, purchase 175.7 million different tickets, and make a nice quick profit of $220 million or so? It’s easy money.

Read the rest of this entry »

Posted in Lottery | 2 Comments »