Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!

Kaush Kane

Ranch Hand
+ Follow
since May 22, 2006
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kaush Kane

Hi All,
In my operation I am having 11 threads that have their own Result Set object to process. When I access my these Result Set objects after some time I get SQLException: Exhausted Resultset from all the 11 threads.

Then I tried executing only a single thread. It functions properly and my operation was successful.

Searching through the Internet for this exception I found some articles that said that this exception can occur if you are not accessing your Result Set properly (i.e. not using resultset.next() or closing the result set etc). But as my single thread operation was successful I dont think any of these as cause of my issue.

I found one post on this forum where it was said that this error might occur if lots of Result Sets are open at the same time. This seems to be the possible cause of the issue I am facing. Apart from the 11 threads that their own Result Set object there would be some other operations as well going on on my system as this is a large application.
Also when I execute a single thread then my operation executes successfully, this strongs suggests me that lots of Result Sets being open at the same time to be the cause of issue I am facing.


Could you please let me know your ideas on this?
Also is there any way I can overcome this issue?
One way I read is by closing the Result Set object as soon as after being used. But that we are already doing in the application. Is there any other way to overcome this?

Please let me know.

Thanks and regards,
Kaustubh Kane
Hi,
I am running a unix shell script from Java Application. I want to catch the Standard output of that process and write to a particular file. But the file that is getting generated is a zero size file. Could you please help.
Please find the following sample code.

12 years ago
Hi Edward,
Ok. Got your point. My implementation had issues.
But I have one doubt though.

Say I have three threads. My first thread failed and hence it forces the latch count to zero. This will make sure that my Main thread does not wait for the remaining threads.

But here the issue is the remaining threads would still continue to run. Requirement is that i need to kill remaining threads if one of the thread fails.

Please let me know.
Hi edward,
Could you please give me more info.
Thanks a lot for all your suggestions. I am planning to use the CountDownLatch.

Following is the sample code. Could you please do a quick review and give your comments:


/* This is my Main thread */
CountDownLatch startSignal = new CountDownLatch(1);
CountDownLatch doneSignal = new CountDownLatch(3);

ToolThread[] runThread = new ToolThread[3]
for (int i = 0; i < 3; i++) {
runThread[i] = new ToolThread(i);
runThread[i].start();
startSignal.countDown(); // let all threads proceed
int return = runThread[i].getStatus();
if (return != 0) {//this means error
// forcing the latch count to zero
for (; doneSignal.getCount() > 0; doneSignal.countDown()){}
}
doneSignal.await(); // wait for all to finish

}




class ToolThread extends Thread {
private final CountDownLatch startSignal;
private final CountDownLatch doneSignal;
private int status;

ToolThread(CountDownLatch startSignal, CountDownLatch doneSignal) {
this.startSignal = startSignal;
this.doneSignal = doneSignal;
}

public int getStatus(){
return status;
}
public void run() {
try {
startSignal.await();
status = doWork();
doneSignal.countDown();
}
catch (InterruptedException ex) {}
}

}

Hello,
I am designing a thread based application where the Main thread is spawning 3 different threads. In the main thread I am waiting for each thread to finish using the "join()" method.

I need to enhance this logic so that if any of the three threads fail then it should be reported to the Main thread and then Main thread should kill the remaining two threads.

How can I achieve this? How can my Main thread know which thread has failed and which two threads to kill. Please find my sample code below:


/* This is my Main thread */
ToolThread[] runThread = new ToolThread[3]
for (int i = 0; i < 3; i++) {
runThread[i] = new ToolThread(i);
runThread[i].start();
}

for (int j = 0;j<3;j++) {
try {
runThread[i].join();
}
catch (InterruptedException ex) {
}
}



Please let me know.

Regards,
Kaustubh Kane.
thnks a lot.
Oh no. My actual code is different and application specific which I cannot share. hence i wrote an equivalent code and in a hurry used "args"

Thanks a lot for helping.
12 years ago
Hi All,
I am trying to create an array of objects of a particular class in the following manner

class objectArray {
public static void main(String[] args) {
String[] args = {"abc", "123"}
CreateObjArr[args.length] obj;
for (int i=0;i<args.length;i++) {
String str = args[i];

//creating each object differently
obj[i] = new CreateObjArr(args);
obj[i].getString();
}
}
}



The above approach is giving me error "variable obj might not have been initialized"
I know I can create array of objects like this:
CreateObjArr[] obj = new CreateObjArr[4];
But as you can see I am creating each object differently.

Could you help me out finding a way.

Best Regards,
Kaustubh Kane
12 years ago

long currentTime = Calendar.getInstance().getTimeInMillis();
long requiredTime = currentTime + 600000;
while(Calendar.getInstance().getTimeInMillis() < requiredTime)



Thanks for giving your comments on the above approach.

But I was thinking of a situation when the currentTime would reach maximum limit that long can handle and then when I add 600000 to it, then it will face some issue as adding 600000 would mean exceeding the limit of long.

Is this a realistic situation? Would anytime Calendar.getInstance().getTimeInMillis() reach maximum limit that long can handle?

Please give your comments...
12 years ago
For the while condition I doing the following:

long currentTime = Calendar.getInstance().getTimeInMillis();
long requiredTime = currentTime + 600000;
while(Calendar.getInstance().getTimeInMillis() < requiredTime)

Please comment on the above condition.

Also when would I get value of Calendar.getInstance().getTimeInMillis() as 0
i.e. when does the Calendar reset to zero??
12 years ago
Thanks a lot for so quick replies.
Just one more query. How can I run a loop for ten minutes?
I had a look in the Date and Calendar class but I am not able to understand that how can I run a loop for ten minutes.

Progress till now is:
I need help to create condition for while loop in below code

try{
func1();
}
catch(SQLException e){
if (ex.getErrorCode() == 00060){
while (///a condition that will run this for 10 minutes){
try{
func1();
break; // if here means execution was successful hence break.
}catch(SQLException e){
// handling here
Thread.sleep(500);
}

}
}
}

12 years ago
Thanks a lot for so quick replies.
Just one more query. How can I run a loop for ten minutes?
I had a look in the Date and Calendar class but I am not able to understand that how can I run a loop for ten minutes.

Progress till now is:
I need help to create condition for while loop in below code

try{
func1();
}
catch(SQLException e){
if (ex.getErrorCode() == 00060){
while (///a condition that will run this for 10 minutes){
try{
func1();
break; // if here means execution was successful hence break.
}catch(SQLException e){
// handling here
}

}
}
}

12 years ago
Actually I need to implement a logic where:
IF I get an exception of ORA-00060: deadlock detected then I need to re-execute the code which is present in the try block.
I need to do it repeatedly over a peroid of 10 minutes until it becomes successful.

How can I do this?

Please help me out.
12 years ago
Please help me out on this one.
I am having some code in try block.

I am getting an exception of ORA-00060: deadlock detected.
If i get this exception then I want to implement a logic where I want to re-execute the code which is in the try block.
How can this be achieved?

I have following doubt:
Once the exception is thrown the execution will be in the catch block (i.e. out of the try block). Once in catch can we again go back to the try block and re-execute the code. How can this be achieved?

Please help me out.
12 years ago
There's one more important point:
As static methods are not instance methods, they can never be overridden.
13 years ago