Program progression,very very weird problem
I'm writing a sub-section of my program.
This section basically calls "ls".
For each "ls" call there is a Product name associated with it.
I used regular expressions to see if that product is in the "ls" results.
I use various Objects and output handlers to make this process happen.
However, given the same runs (Clicking run without changing anything) I get different results.
So I started commenting out code until it stopped happening and found that there is a breaking point in this random behavior. If I comment enough code it produces the correct output each time.
Here's where it gets weird. When I reach the point where I've comented out enough code, if I put in a time wasting loop such as the following
for(int i = 0; i < 10000; i++);
The random output comes back.
So it seems like after some amount of time my application stops processing the "ls" results.
I realize this explanation is probably bad, but I can't think of a better way to describe whats going on. If anyone has any suggestions I would appreciate it.
Message was edited by:
Paul425
[1152 byte] By [
Paul425a] at [2007-11-27 2:40:00]

A better way would be to produce a small compilable and runnable example that demonstrates the problem and show it to us.
I believe this to be more of a fundamental problem then a coding problem.As I said before the placement of a spinning for loop should not alter output.I dont think an executable example would be helpful.
I dont understand what you are asking so this may not be related but if it you are generating a series of random numbers in a short period of time than read this page first: http://www.cs.geneseo.edu/~baldwin/reference/random.html
in particular:
"However, beware of one thing when you use this constructor: Algorithmic random number generators are not truly random, they are really algorithms that generate a fixed but random-looking sequence of numbers. When you create a random number generator, it initializes its sequence from a value called its "seed". The parameterless constructor for Random uses the current time as a seed, which is usually as good a seed as any other. However, the time is only measured to a resolution of 1 millisecond, so if you create two random number generators within one millisecond of each other, they will both generate exactly the same sequence of numbers.
If you prefer, there is also a constructor for Random that allows you to provide your own seed. You can use any long integer as a seed with this constructor. "
Thanks for the reply.
However, I am not using random numbers anywhere in my application.
I'm executing code chunk (A)
Chunk A uses multiple objects.
But if I add a spinning for loop ( just time wasting code)
to chunk A. The output becomes different everytime.
By output I mean I have a list of files, and this extra execution time causes only a partial list of these files to be displayed.
Please assume that I'm not a *****.
The for loop is in NO WAY effecting my code.
null
Well then, we need to see a small compilable example of the code the replicates the problem
While I understand why you guys want an example, its not relevant.
Ok the following code completely changes my programs output:
for(int i = 0; i < 10000; i++);
Thats it, with out that code my code executes and outputs the correct output.
With that code the output is incomplete and different each time.
So, there's something you are doing wrong. Stop doing that and start doing the right thing instead.
And don't ask for details about that, because I'm going to tell you they aren't relevant.
Seriously. If you want to discuss your code, let's have a look at it. Strange things happen in ordinary-looking code. And you are in denial about that. Let's review your posts: first you said that adding a for-loop that does nothing changed the behaviour of your code. Later you said "The for loop is in NO WAY effecting my code."
Well, obviously those can't both be true. You aren't willing to look at your code with an unbiased view point. So show it to somebody else. Vague hand-waving is going to get you nowhere.
"first you said that adding a for-loop that does nothing changed the behaviour of your code. Later you said "The for loop is in NO WAY effecting my code."
Adding a for loop changed the output of my code.
That for loop is a spinning for loop that does nothing but waste cpu cycles.
The for loop is in no way effecting the code around it.
I dont understand how what I said was contradictory but hopefully I have clearified that.
I'm the first person to admit if I've written bad code. However, I was trying to demonstrate that there are other factors involved.
I believe I did this by inserting a spinning for loop that changed the output of my code.
Why would extra CPU cycles cause code to not execute correctly.
Im looking for more of fundamental java properties.
Okay, you're a troll. I'm not answering you any more.
"Okay, you're a troll. I'm not answering you any more."If nothing else, I got a great laugh from this thread.And for that, I thank you.
By ls you mean you're Runtime.exec()ing? Well, that starts another thread. There are some things you can to do control which thread executes when, but in general, you don't get any say. Adding or removing a spin lock or any other code most certainly can affect how threads get scheduled.
Of course, if you'd just come off your high horse, cooperated, and provided sample code like you were asked, you'd have gotten that answer several posts ago.
> I believe this to be more of a fundamental problem> then a coding problem.It's a fundamental problem in your understanding of multithreading.
I'm using a Process Builder to run the "ls"
Providing sample code really isn't an option because of how complex my code intertwined my code is.
And for that reason I'm not looking for someone else to debug my code.
I'm looking more of general suggestions.
I am using a Process builder to do the single "ls" command.
In general, can this cause the unpredictable output based on execution time?
I dont know what your talking about when you say spin lock.
I mentioned a spinning for loop in my posts, but they are just CPU cycle wasters.
Message was edited by:
Paul425
> I'm using a Process Builder to run the "ls"
>
Probably still starts another thread, but I'm not sure.
> Providing sample code really isn't an option because
> of how complex my code intertwined my code is.
You'll have to be able to narrow it down to a small chunk to debug it anyway. If you can't be bothered to provide an example, why should anybody try to guess what's going on w/ code they can't see? Obviously, you're doing something wrong. Without the code, we don't know what.
> I am using a Process builder to do the single "ls"
> command.
> In general, can this cause the unpredictable output
> based on execution time?
If PB works like Runtime.exec, then it starts another thread. Once multiple threads are involved, all bets are off as far as timing and execution order across threads goes.
> I dont know what your talking about when you say spin
> lock.
for (...) { /* do nothing */}
> I mentioned a spinning for loop in my posts, but they
> are just CPU cycle wasters.
Yes, that's what I was referring to.
Its not a matter of "Can't be bothered to get sample code"
Its a matter of a 5 classes being involved and about a dozen methods.
Compiling example code would not only be relatively difficult for you guys to understand, but it also wouldn't be compilable.
Thats why I'm looking for more general ideas I should investigate.
I also don't want other people to have to debug bad code that I've written.
Does anyone know why a Process builder thread would terminate after a set amount of time?
If all my other code is executing linearly, why would it suddenly stop/generate inconsistant output.
I realize that it is difficult to determine what is going on without code, that's why I'm asking for general ideas.
> Thats why I'm looking for more general ideas I should
> investigate.
Okay, well, you've been given that. Good luck.
From what you've desribed, though, it sounds like it should be very easy to post one or two small classes that, even if they don't reproduce the problem when run, could theoretically do so and show the relevant structure.
jverda at 2007-7-21 20:30:03 >

Yep, you gave me a topic to investiate and I appreciate it.Does anyone else have any ideas?Thanks
From the main class I call an object.
From this object I call the "ls" command using Process Builder
From the outputHandler I read the stdOut and pass each line to another object.
From that object I pass the line to another regEx object
With the regEx object I check to see if it is the file I want
as well as do parsing.
I return whether it is or not to the previous object
I realize that is useless.
But i'm looking at my code and without showing just about all of it, it would also be useless.
Okay. Without seeing any of your code, my first instinct would be to throw away the part where you use Runtime.exec() to execute the ls command and see if it could be replaced by use of plain old Java objects such as java.io.File.
First sorry to for reviving a dead thread.Thanks for suggesting the java.io.File It allowed me to remove the Process Builder, which minimizes threads.It fixed my problem.You have saved me a lot of time and frustration.Thanks again.Paul