File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Threads and Synchronization and the fly likes Regarding synchroniztion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Regarding synchroniztion" Watch "Regarding synchroniztion" New topic
Author

Regarding synchroniztion

Sachindra Pratap
Ranch Hand

Joined: Jun 03, 2008
Posts: 42
public static void create_RIU(int cnt){
create_RIU_cnt = cnt;
JButton riu = (JButton)RIU_BUTTON.get(create_RIU_cnt);
if (loc_rt[create_RIU_cnt]==0 && riu.getBackground().equals(clr_yellow)){
{
loc_rt[create_RIU_cnt]=1;
// rt_counter++;

udp_connect_string = udpclient[create_RIU_cnt].UDPclientfunc(
"AT**CONNSTART"+"\r\n",ip[create_RIU_cnt],port[create_RIU_cnt]);
if(udp_connect_string != null){
if(udp_connect_string.contains("BUSY")||
udp_connect_string.contains("TRON")||
udp_connect_string.contains("TROFF"))
JOptionPane.showMessageDialog(null,udp_connect_string);
}

// parsing(udp_connect_string);
try {
if (udp_connect_string.contains("CONNECT")) {
for(int column =0; column < 4; column++) {
JButton b = (JButton)RT_BOX.get(column);
if(b.getLabel().equals("")) {
ptt_cnt[column] = create_RIU_cnt;

r_v[column] = new riu_voicecall_thread(column);
r_v[column].setPriority(8);
r_v[column].start();

r_t[column]=new riu_thread(create_RIU_cnt,column);
r_t[column].setPriority(8);
r_t[column].start();

r_c[column]= new riu_thred_connection(create_RIU_cnt,column);
r_c[column].start();

break;
}
}

} else
loc_rt[cnt]=0;
} catch(NullPointerException e){loc_rt[cnt]=0;}
}
}
}


The query how much reliable is the block inside the function is
if function is called in very very less time interval.
And threads inside the function are also static.
Dariusz Kordonski
Ranch Hand

Joined: Jul 11, 2008
Posts: 49
Originally posted by Sachindra Pratap:
// ...

r_v[column] = new riu_voicecall_thread(column);
r_v[column].setPriority(8);
r_v[column].start();

r_t[column]=new riu_thread(create_RIU_cnt,column);
r_t[column].setPriority(8);
r_t[column].start();

r_c[column]= new riu_thred_connection(create_RIU_cnt,column);
r_c[column].start();

// ...


The query how much reliable is the block inside the function is
if function is called in very very less time interval.
And threads inside the function are also static.[/QB]



I guess the above part is the one you're worried about. Well... it is harmless You just start 3 threads from what I see. If you call this multiple times, more threads will simply be started. You must provide more details about your problem - how the implementation of the started threads looks like (e.g. 'riu_voicecall_thread' says nothing about what this thread does after starting; BTW it is better to define your own thread by implementing Runnable and passing it to java.lang.Thread during construction than to extend java.lang.Thread itself). Perhaps you mean that the above method is invoked asynchronously, by multiple threads?
The fact that your reference variables pointing to thread objects are static (not threads themselves, threads cannot be static) is not a problem, because with each invocation you assign a new thread object to them. If it is safe for the variables you pass to them (column, create_RIU_cnt) depends, again, on the things that they do with those variables (i.e. implementation of your threads).
Sachindra Pratap
Ranch Hand

Joined: Jun 03, 2008
Posts: 42
//code:
---------------------------------------------------------------------------
static class riu_voicecall_thread extends Thread{
int column ;
riu_voicecall_thread(int column){
this.column = column;
}

void operator_call_0(int column){
int col = column;
num = null;
switch(col){
case 0: ....instructions
break;
}
String originate = "command";// some command
if(num != null){
if(tcp1.out != null)
tcp1.out.println(originate);
System.out.println(originate);}else{
JOptionPane.showMessageDialog(null,"RT Phoner Not Available");
}
}
void operator_call_1(int column){
int col = column;
num = null;
switch(col){
case 1: ....instructions
break;
}
String originate ="command";// some instructions
if(num != null){
if(tcp1.out != null)
tcp1.out.println(originate);
System.out.println(originate);}else{
JOptionPane.showMessageDialog(null,"RT Phoner Not Available");
}
}

void operator_call_2(int column){
int col = column;
num = null;
switch(col){
case 2:....instructions
break;
}
String originate = "command";//some instructions
if(num != null){
if(tcp1.out != null)
tcp1.out.println(originate);
System.out.println(originate);}else{
JOptionPane.showMessageDialog(null,"RT Phoner Not Available");
}
}

void operator_call_3(int column){
int col = column;
num = null;
switch(col){
case 3: ....instructions
break;
}
String originate = "command";//some instructions
if(num != null){
if(tcp1.out != null)
tcp1.out.println(originate);
System.out.println(originate);}else{
JOptionPane.showMessageDialog(null,"RT Phoner Not Available");
}
}

public void run() {
System.out.println("operator_call column"+ column);
if(column == 0)operator_call_0(0);
else if(column == 1)operator_call_1(1);
else if(column == 2)operator_call_2(2);
else if(column == 3)operator_call_3(3);

}

}
---------------------------------------------------------------------------


query:- POSTED IN ref. to previous query.
Now please tell how much reliable is this thread.
if called frequently,from function.

Actually is wanted to know since the four objects of threads are made.
but since the thread is static ,
do there are chances of variable column getting changed.

Since now i have hard coded.

regards Sachindra.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding synchroniztion