• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Regarding synchroniztion

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//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.
 
Check your pockets for water buffalo. You might need to use this tiny ad until locate a water buffalo:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic