• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Regarding thread excution

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

............code.................

function()
{
//some instruction are sent to some server
//There is thread which is continuosly running at background
//to read the response from the server .
//then in thread some variable are reset.
}
reset_var;

-----------------------
here i want to ask ,that the task which is being performed in thread
i want to get into reset_var, which being set in thread.

So here the query is whether instrunction reset_var,which immediatly
follows the function block, would get the updated value or not.

if not then please suggest any way how to cope with such prob.


regards sachindra
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is this java that you are talking about?
Can you post real code

What is the meaning of an instruction after a function block?

Are you talking about a member variable being initialized after a method definition?
If yes, then in java all member variable initialization happens first and then method execution starts.
 
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
Thanks for your reply,

Actually function consist of java instruction
for call establishment with sip server.

Well there is a thread ,which is running all the
time when application is up.
Note :And this thread is not running inside the
function block.
The purpose of thread is to read the response,
of instructio being sent in the mentioned function.

So when appropriate reply comes from server, on response to
request which is being sent in the mentioned function,
there is variable which is being set.

And that particular variable is checked just after that function.
so what would be the state of that variable.


regards sachindra
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is all so esoteric, please give some solid example with some real code. This should be a SSCCE program, just enough to give us an idea of the problem you are having, but it needs to be complete enough that we can copy it and run it ourselves.

If you wanted a short answer to:
"whether instrunction reset_var,which immediatly
follows the function block, would get the updated value or not"

The answer is: Yes, if you set it up to be able to be gotten, or No, if not.
[ August 21, 2008: Message edited by: Steve Luke ]
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are talking about the visibility gurarantees of a variable across two threads, then you can make the variable volatile.

For more on visibility guarantees, refer to the Java Memory Model.

If it is in the same thread then the latest value will always be available.
 
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
Thankyou ,Steve and Nishant.
I have found out some solution to the above mentioned proble by making use
of join().
But now i am facing a new logical problem.

-----------code------------------------

t1.start();
t2.start();
t3.start();

////////

thread t1{
public void run(){
//fires some command to
........//instruction send to server
t1.stop();
}
}

thread t2{
public void run(){
while(true){
t1.join();
if(callFlag){//callFlag value set to true only
//when requiste response is read from server through our client prog.
//which is reply of the instrunction send in thread t1;
......
callFlag=false;
t2.stop();
}
}}
}

thread t3{
public void run(){
t2.join();
.....
......
}
}

//Well problem i am facing is suppose the desired response never comes
the callFlag is never set to true;
so the thread t2 never stops .

So please help me out.


regards
Sachindra
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As already mentioned, please post real code. Posting pseudo-code, and then expecting specific answers about the real (not posted) code is just not going to work.

Henry
 
Steve Luke
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, to get a specific answer we will need to see real code.

And pleas use the code tags to display the code (there is a code button at the bottom of the editor).

Generally, though, this is a design question you have to answer. What do you think should happen if the response isn't made? How do you know that the correct response isn't made? When do you know the correct response isn't made?

Is the first line of code in each run method actually a join() with the previous thread? If so, then what benefit do you have of making them separate threads? Why not make them all execute in the same thread?

It also sounds like you may be implementing some sort of event call-back mechanism. For example, Thread 1 is chugging along doing some work. When a certain event occurs (correct response is sent) then Thread 2 should do its thing, and when Thread 2 is done then Thread 3 should do its thing. Meanwhile Thread 1 is still chugging along doing more work and may still need to Signal Thread 2 to do its job again.

Does this sound correct?
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if call flag is never set to true than probably you should look at the client code, what is happening there how can anybody tell this from the code that is checking it rather than the code that is setting it.
 
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
Thankyou All of you, for the valuable suggestion.

Steve i solved the problem.


regards,
Sachindra
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic