Saturday, October 13, 2012

Continue learning JAVA (more)

The interest the other night was to have two threads running and doing the same work. One thread is called AntennaThread, the other ReceiverThread. With unlimited time and some real focus, this program would do more than simply System.out.println() the fact it is in a thread along with a date / time stamp. The threads are running in an endless loop with a Thread.sleep(1000) in between each call to do work. There was a similar example out there in Internet land, so a cut/paste with a few adaptions made quick work.

The code sample was coded to run a socket connection out to some url on a port number. Having that work in a thread is a fairly good idea. Provides good overall JAVA experience with treads. So for my needs, the socket code was hacked out and replaced with a call to run an AntennaThread and ReceiverThread. A util class was coded to support the normal set / get methods, specifically a set method to set a polling interval [util.setPolling()] (within the endless loop), funny I had forgot to instantiate the method so my util.getPolling() always returned 0. It polled really quick!

A util.getTime() was added which returns the date / time as 12-Oct-12 12:30:00. Pretty helpful when logging Antenna or Receiver events. The recent work with Calendar c = new Calendar() and Date d = new Date() along with the SimpleDateFormat was very helpful. Every JAVA programmer needs to be familiar with that.

Driving factor behind this interest comes from a typical satellite ground control system. There are antennas the need to be pointed, receivers that need to have frequencies set and a multitude of other devices that require various setting and configurations. It is best to have this automated. The existing system I work on uses complex multi-thread driven device handlers to do this work. Interest is, can this be done with JAVA in a similar high level design.

This file is called t1.java and is a Netbeans project so it can be called up and worked on as needed. Additional work is to bring the socket code back in and have it read some url out there and simply stream in the url text. Even better is to extend the thread into a jPanel / jInternalFrame with a jTextField as the display. Oh, it will need a button or two in order to stop the thread. That would be pretty cool.

No comments:

Post a Comment