Re: Possible easy diagnostic outputting from multiple threads to the
one text frame
Your code seems good but you neglect to call 'pack()'. Also your
example is incomplete, but I'll assume the omitted parts are not
important.
jc_usernet wrote:
I'm back into JAVA again and am curious to know the response from the
It's spelled "Java".
My current solution that I would like to improve on is:
-------------------------------------------------------
// DiagnosticOutput.java
// Class DiagnosticOutput updates JTextArea with output
These comments should have been in a Javadoc comment.
[snip]
This seems to do what I want for now. However it find this wanting
since I always have to create an object
and pass the reference around to all the participating objects.
Why is this a problem?
Is it possible to have a class without the need to explicitly create a
object for the output I want?
Anything's possible.
I am thinking along the lines of a static method like
DiagnosticOutput.put( String stringToAppend )
Static methods are particularly dangerous in a multi-threaded context
such as the one you need this for.
and first time usage creates the object and subsequent usage appends
Lazy initialization is fraught with peril and usually provides no
benefit.
to this hidden (from the application)
object. So all I need do is simply invoke this method at the various
location within the application.
No, that's not all you need do. You also will need to add a bunch of
careful synchronization and spend a lot of time debugging the result
when it turns out that the use of static methods, a static object,
lazy initialization and multiple threads causes either or both of
wrong results or a huge performance bottleneck.
--
Lew