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

if condition

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Frienz!
I am having a problem in how to implement a if statement....

I am opening a connection with the server...
Now the issue is when ever i perform the action of Opening the Connection it returns me a diff. connectionId..
Now wat i want to ask is how to put a condition that when the connection is already open it should not perform the action again,,,
Thanx
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai

just use two threads. one for getting the connection and other for doing the other process. check for the thread cusing "currentThread" method in IF loop and the ELSE part ll do the next section.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ajay's creativity aside, what you probably want to do is to store the object representing a connection (a URLConnection? A Socket?) in a member variable, such that the member variable is available whenever you need the connection object. Say the member is called "connection". Then your code might look like



When you close the connection, you should also set this member variable to null, so it can be reopened properly.

To be truly correct, you'd want to do this in a synchronized block or method, to prevent multiple connections from being created by accident.

Does this make sense?
 
rubbery bacon. rubbery tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic