I can't remember if I asked this question before, excuse me if I have it's been lost in the shuffle.
Anyways, my experience with
thread programming is limited, and I am trying to decide how best to implement threads into my
java chess program. The program is pretty good as far as it goes, but right now it is just a single threaded app. This leads to the following problem.
When I make a move, a command is issued to repaint the board (a JPanel). At the same time, the chess engine (computer brain) starts churning, to calculate the next move. As a result, CPU is hogged, and the board doesn't complete the repaint until the computer makes it's own move.
I figure one solution to this is to have the "chess engine" run in its own thread, with appropriate priority. One other advantage of this is that it will allow the chess engine to think even when it is not it's turn.
I understand there are two ways to do implement a thread, have my engine class extend Thread or implement Runnable. It is my undersatnding that the only real difference between the two is that implementing runnable is preferrable because of flexibility, it won't prevent you from extending another class if you need to. In any event, I don't really have any concerns with how to do either at this point.
Anyways, this is just a hobby project, and for my purposes I prefer to have my engine class extend thread, if practical. I don't think I will need to extend any other class. Future development for this class will include a fairly sophisticated hash table, and also a sophisticated recursive algorithm. As far as I can see, neither of these will require that I extend another class, but on this point I am not 100% certain.
Anyways, I just wanted to bounce these thoughts off of someone, in case there are any major flaws in my thinking that will require major rework down the road, which naturally I want to avoid.
regards.