Resetting all fields/consecutive starts of a program

J

John B. Matthews

Icarus said:
I run gui.Launcher. [begin-loop] I click the "Launch" button. I see
Singleton mutate on stdout. I click the "Exit" button. I see
InitialisierungenKlassen exit with result 42 on stderr. The Launch
button appears. [repeat-ad-libitum] I close the Launcher window, exiting
the program.

I see no opportunity to type in text in the console.

You may find it instructive to watch the process externally using top,
DTrace, or your favorite profiler.

According to the Eclipse debugging tool, the program runs up to the
line [...] and then stalls. This was also what happened when I tried
to get the code piece with the "exec" command to work.
[...]

If thy IDE commandeers stdout, use the command line:

java -cp . gui.Launcher
 
I

Icarus

If thy IDE commandeers stdout, use the command line:

java -cp . gui.Launcher

This gets the same result. o_O

I am sorry, but I still don't completely understand how the streams
work here. The line
while ((s = stdout.readLine()) != null) {
System.out.println(s);
}
is trying to read something from the InputStream of the subprocess,
but what?

And at what point of the code should the other main-method be
accessed? Shouldn't that happen when starting the process?
 
J

John B. Matthews

Icarus said:
This gets the same result. o_O

I am nonplussed.
I am sorry, but I still don't completely understand how the streams
work here. The line
while ((s = stdout.readLine()) != null) {
System.out.println(s);
}
is trying to read something from the InputStream of the subprocess,
but what?

"The stream obtains data piped from the standard output stream of the
process represented by this Process object."

And at what point of the code should the other main-method be
accessed? Shouldn't that happen when starting the process?

I see two OS processes, each having the usual complement of threads
seen in a GUI application.
 
I

Icarus

I am nonplussed.


"The stream obtains data piped from the standard output stream of the
process represented by this Process object."



I see two OS processes, each having the usual complement of threads
seen in a GUI application.

I had some friends run the code and according to them, it is working.
But not here. o_O
It seems I'll have to do the initialization manually.
 
J

John B. Matthews

[...]
I had some friends run the code and according to them, it is working.
But not here. o_O

Very disturbing. I don't recall your OS, but the standard I/O streams
are foundational. I would be interested to learn what might cause such
an anomaly.
It seems I'll have to do the initialization manually.

Reviewing the thoughtful contributions of several others earlier in the
thread, I suspect that some re-factoring would be well worth the effort.
 
I

Icarus

It seems I'll have to do the initialization manually.
Reviewing the thoughtful contributions of several others earlier in the
thread, I suspect that some re-factoring would be well worth the effort.

Manual initialization worked in this case, actually, only two classes
had to be reset. I just had to add a method creating a new instance
object for most of the singletons, and call it every time I restart
the program.

Thank you all for the contributions. I will keep this thread in mind
for any future programs.
 
I

Icarus

     A new instance of a singleton?  Ah, this is obviously some strange
usage of the word "singleton" that I wasn't previously aware of.

It's still a Singleton as in "one instance per run". This is less
error-prone and more extensible than manually overwriting all fields.

This reminds me of the benefits of a static factory method:

<http://www.ddj.com/java/208403883>

Looks interesting, however, I'll have to spend some time to get into
it. Thanks.
 
B

blue indigo

This reminds me of the benefits of a static factory method:

<http://www.ddj.com/java/208403883>

Better be careful, mate -- the "everything is a nail" syndrome will strike
again, and he who once tried to use a singleton to solve every problem
will now eschew public constructors and try to use static factory methods
to solve every problem.

(If you want to *really* tie one of those types in knots, though, suggest
the strategy pattern -- everything will end up calling callbacks to do
everything else, including call callbacks. Don't bother with the visitor
pattern, though, or he'll just tie the codebase in knots with everything
being double-dispatched, and plug merrily on making code that actually
sort of works, but is unmaintainable. :)
 
J

John B. Matthews

<pan.2009.02.18.09.28.54.265625@uatel.com.nospam.bogus.invalid.invalid.i
nvalid>,
blue indigo
Better be careful, mate -- the "everything is a nail" syndrome will
strike again, and he who once tried to use a singleton to solve every
problem will now eschew public constructors and try to use static
factory methods to solve every problem.

Excellent advice. Every pattern contains the seeds of its own
antipattern. Cooper is a bit dated, but each pattern includes a
convenient summary of Consequences, balancing the Truth:

(If you want to *really* tie one of those types in knots, though,
suggest the strategy pattern -- everything will end up calling
callbacks to do everything else, including call callbacks. Don't
bother with the visitor pattern, though, or he'll just tie the
codebase in knots with everything being double-dispatched, and plug
merrily on making code that actually sort of works, but is
unmaintainable. :)

LOL. Some of my other favorites include the eponymous wiki page and
always popular, "How to Write Unmaintainable Code":

<http://en.wikipedia.org/wiki/Anti-pattern>
<http://mindprod.com/jgloss/unmain.html>
 
A

Arne Vajhøj

John said:
<pan.2009.02.18.09.28.54.265625@uatel.com.nospam.bogus.invalid.invalid.i
nvalid>,
blue indigo


Excellent advice. Every pattern contains the seeds of its own
antipattern.

Yes !!

Arne
 
I

Icarus

Just to make sure: I did see all your latest posts, but sort of felt
repetitive in saying "thank you, I'll have a look into it". :)
I should have nonetheless given some kind of feedback that I did
receive the posts. I'm sorry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top