Sun Microsystems V2.0 manual Overview of an application, Threads, Thread priorities

Page 24

Developing and debugging Sun SPOT applications

Overview of an application

A Sun SPOT application is actually implemented as a MIDlet. This should not concern most developers greatly: the simplest thing is to copy a template, as described above, and start editing the copy. The most significant implications of this are covered in the section Manifest and resources.

The Sun SPOT application runs on top of a number of other software components within the Sun SPOT. These include

a bootloader (which handles the USB connection, upgrades to the SDK components, launching applications, and much of the interaction with ant scripts).

a Config page (containing parameters that condition the operation of the bootloader).

a Squawk Java VM (The Squawk VM is the Java virtual machine that runs on the Sun SPOT. For more details, go to http://research.sun.com/projects/squawk/).

a bootstrap suite (containing the standard JME Java classes).

a library suite (containing the Sun SPOT-specific library classes).

The operation of these will generally be transparent to application developers.

Threads

Developers should also be aware that a number of background threads will be running as a result of using the Sun SPOT libraries. These include various threads which manage sleeping (limiting power use where possible), monitor the state of the USB connection, and threads within the radio communication stack. All of these threads run as daemon threads.

One other thread to be aware of is the OTA command server thread: see section Remote operation. This thread may or may not be running according to the configuration of the Sun SPOT, but if it is, it will inhibit applications from exiting normally even after all user threads have stopped running.

Thread priorities

Through the standard contract of the Thread class, Squawk allows threads to be assigned priorities in the range Thread.MIN_PRIORITY (1) to Thread.MAX_PRIORITY (10). Special interfaces allow threads to be given higher priorities known as "system priorities", but these are not intended for application use.

These rules should be adhered to by application developers to ensure correct operation of the libraries:

1.Applications should not use system priorities. If they do, the library may not work.

2.Application threads that are compute-bound should run at a lower priority than Thread.NORMAL. Otherwise they may interfere with the correct operation of the library.

3.Application threads at Thread.MAX_PRIORITY will not normally compete with any library threads, which all run at lower priorities except as detailed below. Note that if library threads are prevented from running then library operation may be affected. In particular, this may either degrade radio performance or cause incoming broadcast traffic to be missed.

24

Image 24
Contents Page Page Contents Http protocol support Introduction Building and deploying Sun Spot applications Deploying and running a sample applicationBuild Successful Total time 3 seconds \MyApplication Ant -Dport=COM2 info Total time 4 seconds \MyApplication Total time 0 seconds \MyApplication Deploying a pre-existing jar Incorporating utility classes into your applicationManifest and resources Excluding files from the compilationOther user properties Using the Basestation Built-in propertiesOverview Set up Base Station configuration Remote operationIntroduction Connect a Sun Spot base station Using short names for SPOTs Managing keys and sharing Sun SPOTsTake suitable actions during over-the-air downloads BackgroundChanging the owner of a Sun Spot Sharing Sun SPOTsWhat is protected? Deploying and running a host applicationGenerating a new key-pair LimitationsConfiguring network features Your own host applicationIncorporating pre-existing jars into your host application Mesh routingHardware configurations and USB power Trace routeLogging Page Overview of an application ThreadsThread priorities Sun Spot device libraries Sun Spot device libraryDevice Interface Persistent properties Accessing flash memory Overriding the Ieee addressUsart Radio communication library Program Radiogram protocol Client end Server endYou can open server radiogram connections in a similar way Broadcasting Radio properties Turning the receiver off and on Conserving power using deep sleep mode Monitoring radio activityShallow Sleep Activating deep sleep mode Deep SleepUSB inhibits deep sleep Preconditions for deep sleepingDeep sleep behaviour of the standard drivers Device Condition to permit deep sleepWriting a device driver Configuring the http protocol Http protocol supportConfiguring projects in an IDE Socket Proxy GUI modeClasspath configuration Javadoc/source configurationDebugging Ant selectapplication Configuring NetBeans as a debug client Configuring Eclipse as a debug clientUsing library suites Advanced topicsWith adderlib as your current directory, execute the command Use the command Using the spot client SpotSerialPortException other exception in serial port comms Reference Persistent system propertiesProperty name Meaning Contents of the arm directory Contents of the lib directoryMemory usage Start address Space UseContents of the bin directory preverify.exe Contents of the upgrade directory Contents of the tests directory