When a static method is accessed concurrently

When a static method is accessed by many objects symultaneously(concurrently),
What is happened in the static method.
Are the stacks for that method maded seperately and
each stack doesn't influence other stacks?
thank you in advance.

The static objects or methods concept is clear, one
instance for all objects.No. One instance for the class.
, and every
one know that, static methods is slower than
nonstatic, Since when? I've certainly never heard that before... Do you have a reference I can look at?
and this is as i thought because static
methods are syncronized by default.Absoloutely not!
All synchronization locks on an object. When you synchronize an instance method, it locks on the implicit "this"; When you synchronize a static method, it locks on the class's associated Class object.
So two synchronized static methods in the same class can not be called at the same time, but synchronized instance methods that access static variables can all access those variables at the same time and potentially cause threading problems. In this situation you can declare the static fields volatile or wrap synchronized blocks around all code that accesses them, and synchronize on the same object (perhaps the Class object associated with the current class would be appropriate, but that reallt depends on the rest of your design).

Similar Messages

  • Static method decisions

    Dear all experts,
    I have got some problems understanding when to use static methods or passing the classes through constructor.
    I have got a class which needs to be accessed by several classes and also the classes inside the classes etc....
    Instead of passing classes around, should I just create a single static class which can be accessed by all the classes without needing to instantiate the class?
    I found that, i particularly in doubt when there are classes like "TableParser", "PropertiesReader" etc which some classes deep down in the hierarchy need access to those classes...
    Also, making the class static would it decrease the security of the whole program?? Say if i have got an encrytion class which does all the encrypt and decrypt, if i let it be static, isn't it easier to let people accessing the method? the same applies to properties editor etc??
    Any help would be really appreciated.
    Thx

    thx again jverd... (remember the security question? :)
    )I remember your id, but I didn't recall which thread(s) I had seen it in.
    >
    based on the understanding of what you said, do you
    mean that, if i am only using a class to store or read
    a setting file, it's ok to let it static? (so that all
    classes can access it whenever they like without
    passing the parser class to classes?)Um, again, you're terminology's a little off, so I'm not sure exactly what you mean, and even the description "store or read a seting file" could have a couple of interpretations.
    For example....You read the file once, and the config data it constains is accessible throughout your app and never changes. This might be a candidate for a class that only had static methods, but it would be kind of inflexible. What if later some other part of your app, or some other library that you develop that your app is going to use, wants to get its configuration from a file. In that case, I might want to have a couple instances of that class around. One for the global config that reads one file, and another for the config for that library that might read another file.
    I'd probably not even think about it as "reading a settings file." Rather, I'd see that as two parts: providing config settings to the app via a class, and reading a file to populate that class. The settings would exist independent of the fact that you can populate them from a file.
    I'd think about how I want to use them and decide whether to instantiate the class or use static methods based on that. Separately, I'd think about how this class or an instance of it is gonna get popuated with data from outside the program.
    I might decide to have different instances hold different sets of config data, and therefore use instance (non-static) methods to access the data in each of those instances, but I might register the instances--say by name, or maybe just in a list--and I could use a static method to acess the map or list: Config dbConfig = Config.getConfig("database"); Also, I wouldn't generally make a decsision on whether to use class methods or instance methods based on not having to pass a parameter.
    If you're thinking "I'd like to use static because it's easier. Can I get away with it here," then you're viewing objects as a burden to be avoided, which kind of defeats the purpose of using OO techniques in the first place.

  • Why is it necessary to create an instance via the static method?

    Hi,
    For some classes (such as java.util.regex.Pattern), we should call the class method (static method) in order to create an instance (object).
    For example, in order to conduct the pattern matching, we should use the java.util.regex.Pattern class as follows:
    Pattern p = Pattern.compile ("X[0-9]+X") ;
      // An instance of the Pattern class is created.
    Matcher m = p.matcher ("abcX1XYX23Xz") ;
    while ( m.find() ){
      System.out.println ( m.start() ) ;
    }where the compile static method in the Pattern class creates an instance and returns the pointer (reference) of it. We should NOT call
    the constructor of the Pattern class as follows:
    Pattern p = new Pattern ("X[0-9]+X") ;    // ERRORThe question is the following:
    (1) In what scenes, do we develop the classes that force users to call the static method for creating an instance of it?
    (2) Why do the java.util.regex.Pattern class have such a specification?
    Thanks in advance.

    (1) In what scenes, do we develop the classes that force users to call the static method for creating an instance of it?1. As the other author mentioned, caching is one reason.
    2. With such caching, you don't need to take trouble in passing the reference of a cached object(s) to many places in your code. From anywhere in your code base, you can simply invoke the method, the object will come. In essence, the static method provides a global point of access to one or more pre-created (or cached) objects. Hence, the static method simplifies access to the object.
    3. Sometimes, the actual class instantiated is not the same as the one with the static method. This allows abstraction of underlying variations. For example, when you say Pattern.compile ("X[0-9]+X") , the returned object type can be different in Windows and Linux (Most probably Pattern class doesn't work like that, but I am showing you a use case. May be Runtime.getRuntime() does actually work like that.). You find this abstraction of variations in many places. Take for example, FacesContext.getExternalContext() method (this is from JSF API). ExternalContext documentation says this:
    "This class allows the Faces API to be unaware of the nature of its containing application environment. In particular, this class allows JavaServer Faces based appications to run in either a Servlet or a Portlet environment."
    Edited by: Kamal Wickramanayake on Oct 24, 2012 8:04 AM

  • How to determine the Class of a static methods class?

    hi,
    is there a way to get the code below to output
    foo() called on One.class
    foo() called on Two.classthanks,
    asjf
    public class Two extends One {
       public static void main(String [] arg) {
          One.foo(); // should say "foo() called on One.class"
          Two.foo(); // should say "foo() called on Two.class"
    class One {
       public static final void foo() {
          System.out.println("foo() called on "/*+something.getClass()*/);
    }

    - One.class won't resolve to Two.class when the static
    method is called via the class TwoThat's because static methods are not polymorphic. They cannot be overridden. For example try this:
    public class Two extends One {
       public static void main(String [] arg) {
          One.foo(); // should say "foo() called on One.class"
          Two.foo(); // should say "foo() called on Two.class"
          One one = new Two();
          one.foo();
          ((Two) one).foo();
       public static void foo() {
          System.out.println("foo() called on Two");
    class One {
       public static void foo() {
          System.out.println("foo() called on One");
    }

  • Synchronized method not preventing concurrent access

    Hi
    I have 3 classes, T (a Runnable), TRunner (instantiates and starts a thread using T), and Sync (with one synchronized method, foo).
    The problem is that foo is entered concurrently by different threads at the same time. How so?
    T.java:
    import java.util.Calendar;
    class T implements Runnable
       private String name;
       public T(String name)
         this.name = name;
       public void run()
          Thread.currentThread().setName(name);
          Sync s = new Sync();
          System.out.println(Calendar.getInstance().getTime() + ".....Running " + Thread.currentThread().getName());
          s.foo(name);
    }TRunner.java:
    class TRunner
       public static void main(String args[])
           T tx = new T("x");
           T ty = new T("y");
           T tz = new T("z");
           Thread t1 = new Thread(tx);
           Thread t2 = new Thread(ty);
           Thread t3 = new Thread(tz);
           t1.start();
           t2.start();
           t3.start();
    }Sync.java:
    import java.util.Calendar;
    class Sync
       public synchronized void foo(String threadname)
              System.out.println(Calendar.getInstance().getTime() + ":" + threadname + "....entering FOO");
              try
                   Thread.sleep(5000);
              catch (InterruptedException e)
                   System.out.println("interrupted");
              System.out.println(Calendar.getInstance().getTime() + ":" + threadname + "....leaving FOO");
    }Console output:
    C:\javatemp>java TRunner
    Mon Apr 09 15:35:46 CEST 2007.....Running x
    Mon Apr 09 15:35:46 CEST 2007:x....entering FOO
    Mon Apr 09 15:35:46 CEST 2007.....Running y
    Mon Apr 09 15:35:46 CEST 2007:y....entering FOO
    Mon Apr 09 15:35:46 CEST 2007.....Running z
    Mon Apr 09 15:35:46 CEST 2007:z....entering FOO
    Mon Apr 09 15:35:51 CEST 2007:x....leaving FOO
    Mon Apr 09 15:35:51 CEST 2007:y....leaving FOO
    Mon Apr 09 15:35:51 CEST 2007:z....leaving FOO
    C:\javatemp>Thanks in advance.

    Only for static methods. For instance methods, the lock >is the object.You are absolutely right.
    The Class object is no different from any other object. >"Entire" Class object makes no sense.What I wanted to say is that it's better to synchronize on the object we want to protect from concurrent access rather than on the entire class or instance object.
    "Efficiency" is not altered by locking on a Class object vs. >any other object.I studied that it's better to synchronize on the objects we want to protect instead of the entire instance or class object. If one declares a method as synchronized, it means that other threads won't be able to access other synchronized methods for the same object, even if the two weren't in conflict. That was explained as a performance penalty.
    >
    Or when one or more threads may modify it and one or
    more may read it.
    Yep, sure.
    >
    No, they're not.
    You are absolutely right. What I wanted to say is that local variables are unique per thread.
    >
    Local variables are unique per thread, but that's NOT
    atomicity.Sorry for any confusion
    Message was edited by:
    mtedone

  • Static methods in concurrency

    I have a static method which takes a few String and double parameters and contains only local variables. When it is called by multiple threads there seems to be an exception thrown intermittenly. I got a little paranoid and so I've changed it to an instance method, and now the problem seems to disappear.
    Is this just a coincidence? Is my static method intrinsically thread-safe? Or are there any concurrency issues with static methods that I'm not aware of?
    Any reply is much appreciated!

    public static net.opengis.sos.v_1_0_0.InsertObservationResponse insertObservation(String serverURL, String AssignedSensorId, String dataType, String timeFrom, String timeTo, String srsName, double x, double y, long numElement, String dataString) throws MalformedURLException, IOException, JAXBException, ParserConfigurationException {
            OutputStream out = null;
            InputStream in = null;
            try {
                URL url = new URL(serverURL);
                HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                connection.setDoOutput(true);
                connection.setRequestMethod("POST");
                connection.setRequestProperty("Content-type", "text/xml, application/xml");
                out = connection.getOutputStream();
                JAXBContext jaxbContext = JAXBContext.newInstance("net.opengis.sos.v_1_0_0:net.opengis.ows.v_1_1_0:net.opengis.sos.v_1_0_0.filter.v_1_1_0:net.opengis.sensorml.v_1_0_1:net.opengis.swe.v_1_0_1:net.opengis.om.v_1_0_0:net.opengis.gml.v_3_1_1:net.opengis.sampling.v_1_0_0");
                /////////////////////////////////request
                Marshaller marshaller = jaxbContext.createMarshaller();
                marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
                //////////////////////////////////////object factories
                net.opengis.gml.v_3_1_1.ObjectFactory gmlOF = new net.opengis.gml.v_3_1_1.ObjectFactory();
                net.opengis.swe.v_1_0_1.ObjectFactory sweOF = new net.opengis.swe.v_1_0_1.ObjectFactory();
                net.opengis.sampling.v_1_0_0.ObjectFactory saOF = new net.opengis.sampling.v_1_0_0.ObjectFactory();
                ////////////////////////////////////////////////////////////////////////////////////////////////getObservation request
                net.opengis.sos.v_1_0_0.InsertObservation insertObservation = new net.opengis.sos.v_1_0_0.InsertObservation();
                insertObservation.setAssignedSensorId(AssignedSensorId);
                net.opengis.om.v_1_0_0.ObservationType observation = new net.opengis.om.v_1_0_0.ObservationType();
                ///////////////////////////////om:samplingTime
                //begin position
                net.opengis.gml.v_3_1_1.TimePositionType beginTimePosition = new net.opengis.gml.v_3_1_1.TimePositionType();
                beginTimePosition.getValue().add(timeFrom);
                //end position
                net.opengis.gml.v_3_1_1.TimePositionType endTimePosition = new net.opengis.gml.v_3_1_1.TimePositionType();
                endTimePosition.getValue().add(timeTo);
                //time period
                net.opengis.gml.v_3_1_1.TimePeriodType timePeriod = new net.opengis.gml.v_3_1_1.TimePeriodType();
                timePeriod.setBeginPosition(beginTimePosition);
                timePeriod.setEndPosition(endTimePosition);
                net.opengis.swe.v_1_0_1.TimeObjectPropertyType timeObjectPropertyType = new net.opengis.swe.v_1_0_1.TimeObjectPropertyType();
                timeObjectPropertyType.setTimeObject(gmlOF.createTimePeriod(timePeriod));
    //            timeObjectPropertyType.setTimeObject(new JAXBElement(new QName("http://www.opengis.net/gml", "name"), net.opengis.gml.v_3_1_1.TimePeriodType.class, timePeriod));
                observation.setSamplingTime(timeObjectPropertyType);
                /////////////////////////////////om:procedure
                net.opengis.om.v_1_0_0.ProcessPropertyType processPropertyType = new net.opengis.om.v_1_0_0.ProcessPropertyType();
                processPropertyType.setHref(AssignedSensorId);
                observation.setProcedure(processPropertyType);
                /////////////////////////////////om:observedProperty
                net.opengis.swe.v_1_0_1.CompositePhenomenonType compositePhenomenonType = new net.opengis.swe.v_1_0_1.CompositePhenomenonType();
                compositePhenomenonType.setId("cpid0");
                compositePhenomenonType.setDimension(BigInteger.ONE);
                net.opengis.gml.v_3_1_1.CodeType codeType = new net.opengis.gml.v_3_1_1.CodeType();
                codeType.setValue("resultComponents");
                compositePhenomenonType.getName().add(new JAXBElement(new QName("http://www.opengis.net/gml", "name"), net.opengis.gml.v_3_1_1.CodeType.class, codeType));
                net.opengis.swe.v_1_0_1.PhenomenonPropertyType phenomenonPropertyType1 = new net.opengis.swe.v_1_0_1.PhenomenonPropertyType();
                phenomenonPropertyType1.setHref("urn:ogc:data:time:iso8601");
                compositePhenomenonType.getComponent().add(phenomenonPropertyType1);
                net.opengis.swe.v_1_0_1.PhenomenonPropertyType phenomenonPropertyType2 = new net.opengis.swe.v_1_0_1.PhenomenonPropertyType();
                phenomenonPropertyType2.setHref("Abfluss");
                compositePhenomenonType.getComponent().add(phenomenonPropertyType2);
                net.opengis.swe.v_1_0_1.PhenomenonPropertyType observedProperty = new net.opengis.swe.v_1_0_1.PhenomenonPropertyType();
                observedProperty.setPhenomenon(sweOF.createCompositePhenomenon(compositePhenomenonType));
                observation.setObservedProperty(observedProperty);
                ////////////////////////////////om:featureOfInterest
                net.opengis.sampling.v_1_0_0.SamplingPointType samplingPoint = new net.opengis.sampling.v_1_0_0.SamplingPointType();
                samplingPoint.setId(AssignedSensorId);
                net.opengis.gml.v_3_1_1.CodeType saName = new net.opengis.gml.v_3_1_1.CodeType();
                saName.setValue(AssignedSensorId);
                samplingPoint.getName().add(new JAXBElement(new QName("http://www.opengis.net/gml", "name"), net.opengis.gml.v_3_1_1.CodeType.class, saName));
                //samplingPoint.getSampledFeature().add(gmlOF.createFeaturePropertyType());
                net.opengis.gml.v_3_1_1.DirectPositionType pos = new net.opengis.gml.v_3_1_1.DirectPositionType();
                pos.setSrsName(srsName/*"urn:ogc:def:crs:EPSG:4326"*/);
                pos.getValue().add(x);
                pos.getValue().add(y);
                net.opengis.gml.v_3_1_1.PointType point = new net.opengis.gml.v_3_1_1.PointType();
                point.setPos(pos);
                net.opengis.gml.v_3_1_1.PointPropertyType pointProperty = new net.opengis.gml.v_3_1_1.PointPropertyType();
                pointProperty.setPoint(point);
                samplingPoint.setPosition(pointProperty);
                net.opengis.gml.v_3_1_1.FeaturePropertyType featureMember = new net.opengis.gml.v_3_1_1.FeaturePropertyType();
                featureMember.setFeature(saOF.createSamplingPoint(samplingPoint));
                net.opengis.gml.v_3_1_1.FeatureCollectionType featureCollectionType = new net.opengis.gml.v_3_1_1.FeatureCollectionType();
                featureCollectionType.getFeatureMember().add(featureMember);
                net.opengis.gml.v_3_1_1.FeaturePropertyType featureOfInterest = new net.opengis.gml.v_3_1_1.FeaturePropertyType();
                featureOfInterest.setFeature(gmlOF.createFeatureCollection(featureCollectionType));
    //            featureOfInterest.setFeature(new JAXBElement(new QName("http://www.opengis.net/gml", "name"), net.opengis.gml.v_3_1_1.FeatureCollectionType.class, featureCollectionType));
                observation.setFeatureOfInterest(featureOfInterest);
                DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                factory.setNamespaceAware(true);
                DocumentBuilder builder = factory.newDocumentBuilder();
                Document doc = builder.newDocument();
                final String sweNS = "http://www.opengis.net/swe/1.0.1";
                Element dataArray = doc.createElementNS(sweNS, "swe:DataArray");
                Element elementCount = doc.createElementNS(sweNS, "swe:elementCount");
                Element count = doc.createElementNS(sweNS, "swe:Count");
                Element value = doc.createElementNS(sweNS, "swe:value");
                dataArray.appendChild(elementCount).appendChild(count).appendChild(value).appendChild(doc.createTextNode(String.valueOf(numElement)));
                Element elementType = doc.createElementNS(sweNS, "swe:elementType");
                elementType.setAttribute("name", "Components");
                Element simpleDataRecord = doc.createElementNS(sweNS, "swe:SimpleDataRecord");
                Element timeField = doc.createElementNS(sweNS, "swe:field");
                timeField.setAttribute("name", "Time");
                Element time = doc.createElementNS(sweNS, "swe:Time");
                time.setAttribute("definition", "urn:ogc:data:time:iso8601");
                Element featureField = doc.createElementNS(sweNS, "swe:field");
                featureField.setAttribute("name", "feature");
                Element text = doc.createElementNS(sweNS, "swe:Text");
                text.setAttribute("definition", "urn:ogc:data:feature");
                Element dataField = doc.createElementNS(sweNS, "swe:field");
                dataField.setAttribute("name", dataType);
                Element quantity = doc.createElementNS(sweNS, "swe:Quantity");
                quantity.setAttribute("definition", dataType);
                Element uom = doc.createElementNS(sweNS, "swe:uom");
                uom.setAttribute("code", "m3 per s");
                simpleDataRecord.appendChild(timeField).appendChild(time);
                simpleDataRecord.appendChild(featureField).appendChild(text);
                simpleDataRecord.appendChild(dataField).appendChild(quantity).appendChild(uom);
                dataArray.appendChild(elementType).appendChild(simpleDataRecord);
                Element encoding = doc.createElementNS(sweNS, "swe:encoding");
                Element textBlock = doc.createElementNS(sweNS, "swe:TextBlock");
                textBlock.setAttribute("decimalSeparator", ".");
                textBlock.setAttribute("tokenSeparator", ",");
                textBlock.setAttribute("blockSeparator", ";");
                dataArray.appendChild(encoding).appendChild(textBlock);
                Element sweValues = doc.createElementNS(sweNS, "swe:values");
                dataArray.appendChild(sweValues).appendChild((doc.createTextNode(dataString)));
                Element result = doc.createElementNS("http://www.opengis.net/om/1.0", "om:result");
                result.appendChild(dataArray);
                observation.setResult(result);
                insertObservation.setObservation(observation);
                //handle "ogc" namespace bug
                NamespacePrefixMapper mapper = new PreferredMapper();
                marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);
                marshaller.marshal(insertObservation, System.out);
                marshaller.marshal(insertObservation, out);
                Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
                in = connection.getInputStream();
                Object response = unmarshaller.unmarshal(new StreamSource(in));
                if (response instanceof net.opengis.sos.v_1_0_0.InsertObservationResponse) {
                    return (net.opengis.sos.v_1_0_0.InsertObservationResponse) response;
                } else if (response instanceof net.opengis.ows.v_1_1_0.ExceptionReport) {
                    net.opengis.ows.v_1_1_0.ExceptionReport exceptionReport = (net.opengis.ows.v_1_1_0.ExceptionReport) response;
                    StringBuilder strBuilder = new StringBuilder();
                    for (net.opengis.ows.v_1_1_0.ExceptionType ex : exceptionReport.getException()) {
                        StringBuilder tempBuilder = new StringBuilder(ex.getExceptionCode() + ": ");
                        for (String temp : exceptionReport.getException().get(0).getExceptionText()) {
                            tempBuilder.append(temp + "\n");
                        strBuilder.append(tempBuilder.toString() + "\n");
                    throw new IllegalArgumentException(strBuilder.toString());
                } else {
                    throw new IllegalStateException("Unrecognizeable response type!");
            } finally {
                if (out != null) {
                    out.close();
                if (in != null) {
                    in.close();
        }Edited by: 808239 on 10-Feb-2011 02:44

  • Static methods in data access classes

    Are we getting any advantage by keeping functions of DAOs (to be accessed by Session Beans) static ?

    I prefer to have a class of static methods that
    require a Connection to do their work. Usually, there
    is a SessionBean that 'wraps' this DAO. The method
    signatures for the SSB are the same, minus the need
    for a Connection, which the SSB gets before delegating
    to the Static Class.Uggh, passing around a connection. I've had to refactor a bunch of code that used this pattern. We had classes in our system that took a class in their constructor simply because one of their methods created an object that needed the connection. Bad news--maintenance nightmare--highly inflexible.
    What we've done is create ConnectionFactory singletons that are used throughtout the application in order to get connections to the database. All connection factory implementations implement the same interface so they can be plugged in from other components at runtime.
    In my opinion, classes that use connections should manage them themselves to ensure proper cleanup and consistent state. By using a factory implementation, we simply provide the DAO classes the means by which they can retrieve connections to the database and even the name of the database that needs to be used that is pluggable. The DAO classes do their own connection management.
    For similar reasons, I eschew the static method concept. By using class methods, you make it difficult to plug in a new implementation at runtime. I much prefer the singleton pattern with an instance that implements a common interface instead of a class full of static methods.
    I recently needed to dynamically plug in new connection factory implementation so that we could use JNDI and DataSources within the context of the application server (pooled connections) but use direct connections via the Driver manager for unit testing (so the application server didn't need to be running). Because of the way this was coded, I simply changed the original factory to be an abstract factory and changed the getInstance() method to return a different implementation based on the environment (unit test vs live). This was painless and didn't require changing a single line of client code.
    If I had to do this using the previous code that I refactored, I would have had to change about 200 jsp pages and dozens of classes that were making calls to the static method of the previous factory or hacked in something ugly and hard to maintain.
    YMMV

  • Dynamic programming accessing static method on classes

    Hi
    I need access to a static method on a class.
    The class name is first decided at runtime.
    How do I do that?
    Regards,
    Morten

    Hello Morten
    Here is a sample program for you:
    *& Report  ZUS_SDN_DYNAMIC_METHOD_CALL
    REPORT  zus_sdn_dynamic_method_call.
    DATA: go_msglist    TYPE REF TO if_reca_message_list.
    DATA: gd_method     TYPE tmdir-methodname,
          gd_class      TYPE seoclsname.
    START-OF-SELECTION.
      IF ( 1 = 2 ).
        CALL METHOD cf_reca_message_list=>create
    *      EXPORTING
    *        id_object    = 'RECA'
    *        id_subobject = 'MISC'
    *        id_extnumber =
          RECEIVING
            ro_instance  = go_msglist.
        go_msglist = cf_reca_message_list=>create( ).
      ENDIF.
      gd_class  = 'CF_RECA_MESSAGE_LIST'.
      gd_method = 'CREATE'.
      CALL METHOD (gd_class)=>(gd_method)
        RECEIVING
          ro_instance = go_msglist.
      IF ( go_msglist IS BOUND ).
        WRITE: / 'Class is bound'.
      ELSE.
        WRITE: / 'Class is NOT bound'.
      ENDIF.
    END-OF-SELECTION.
    Obviously, that is only half of the task. You need to make the method signature dynamically as well.
    Regards
      Uwe

  • I am not able access static methods from startup class

    I have a simple java class which queries the Database and holds some data. I am trying to access a static method of this class from the StartupClass and I am not able to do so. But I am able to access a static variable of the same class.
    Can someone help me here.

    Well, welcome to the world of "hacked" phones. If your purchase was from the US, you obviously purchased an iPhone that is locked to a US carrier. The iPhone must have been jailbroken and unlocked via software to accommodate your foreign SIM card. Now that you have updated the phone, it is locked back to the US carrier. Only the carrier can authorize Apple to unlock the iPhone and none of the US carriers will unlock the iPhones. Best suggestion is to sell the phone and obtain a factory unlocked version directly from the Apple store.
    To answer your other question, there is not a supported method to downgrade iOS.

  • Static methods and how to access

    Hi,
    This seems like a silly quesion but i am trying to access a static method but it tells me that i cant.
    The method i am calling from is not static
    Thanks

    syntax: class name dot static method name (assuming the method is accessible): StaticMethodClassName.aStaticMethod();
    can't reference a class member (variable, object, method, ...) from a static method because a static method is not a class member (it is simply a method whose scope is confined to that of the class in which it is defined).
    example:
    class Foo
    int i;
    public static void hasSyntaxErr() // this method is not a member of Foo
    i = 0; // not allowed because i is a member of Foo
    class Fooo
    void testStatic() { Foo.hasSyntaxErr(); }
    }

  • [svn:fx-trunk] 10891: Fix for ASDoc throws error when using getter methods for pseudo-inheritance of static constants

    Revision: 10891
    Author:   [email protected]
    Date:     2009-10-06 09:46:47 -0700 (Tue, 06 Oct 2009)
    Log Message:
    Fix for ASDoc throws error when using getter methods for pseudo-inheritance of static constants
    QE notes: None.
    Doc notes: None
    Bugs: SDK-22676
    Tests run: checkintests
    Is noteworthy for integration: No
    Ticket Links:
        http://bugs.adobe.com/jira/browse/SDK-22676
    Modified Paths:
        flex/sdk/trunk/modules/compiler/src/java/flex2/compiler/asdoc/AsDocUtil.java

    Have you tried using com.adobe.air.crypto.EncryptionKeyGenerator instead?

  • Initializer block not called when static method called

    public class Initializer {
         Initializer(){
              System.out.println("Constructor called");
                   System.out.println("CLASS INITIALIZED");
         static void method(){
              System.out.println("Static method called");
         public static void main(String[] args) {
              Initializer.method();
    From the JLS
    A class or interface type T will be initialized immediately before the first occurrence of any one of the following:
    T is a class and an instance of T is created.
    T is a class and a static method declared by T is invoked.
    [b]
    But when i call the static method , if the class is initialized shouldnt the initializer block be called, it is not called, why.

    Perhaps running something like this will add a little more colour?:
    public class Initializer {
        static {
            System.out.println("First static initializer");
            System.out.println("First instance initializer");
        Initializer() {
            System.out.println("Constructor");
        static {
            System.out.println("Second static initializer");
            System.out.println("Second instance initializer");
        static void staticMethod() {
            System.out.println("staticMethod");
        void instanceMethod() {
            System.out.println("instanceMethod");
        public static void main(String[] args) {
            System.out.println("main");
            staticMethod();
            new Initializer().instanceMethod();
    }

  • Access to Class information from a static method

    There does not appear to be anyway to access the Class object from instead a static method.
    e.g. How could I convert the following code so that it works ?
    class test {
    static void printClassName() {
    System.out.println( getClass().getName() );

    The idea was to have a static method that could be
    used to make a lookup based on the classname. Being
    able to access the class name would mean that I would
    not have to reimplement for every subclass !!!!!Hmm.. what are you trying to look up? Some kind of class-specific constant information maybe?
    In general your best bet is to define an abstract method in your parent class for return of the constant value, then define a specific method in each sub-class that overrides it, retrurning the appropriate value.
    Then you're common processing just gets the value with that method.
    Using some kind of lookup on the basis of class name is much clumsier, and more inclined to run time errors. Better to use the built in virtual methods table.
    Another approach is to have the value as a parameter of the constructor of the parent class and use "super(value)" in the child classes to store
    it.

  • Static methods in class accessed by jsp/servlet

    I wanted to conceptually know ...
    If I have a class specifically doing some quering to database and giving results to jsp and servlet ... does this make sense? Static methods are ok ? Is it secure enough if I have all connection classes local to a method? can i make the connection global instead without compromising security ?
    For example:
    public class DatabaseUtility{
    public static Sring getUsername(String employeeid)
      Connection conn = ...........
      Statement stmt = ........
    rs executes query and gets a username and returns it...
    public static Sring getAddress(String employeeid)
      Connection conn = ...........
      Statement stmt = ........
    rs executes query and gets a address and returns it...
    }

    can i make the connection global instead without compromising security ?As long as it was readonly, it should be secure. However as damiansutton said, you open yourself up to a resource bottleneck if you make the connection static, as everyone will be using the same connection.
    Most often if you want one piece of information from this DatabaseUtility, you want more than one. Why get a database connection each time? You want to get a DB connection, milk all the info you want from it, and then give it back.
    I think you might want to look at having a DataAccessObject: http://java.sun.com/blueprints/corej2eepatterns/Patterns/DataAccessObject.html
    It is no longer static, but is much more efficient in that it only creates one database connection for all your queries on one request. So anywhere you want to use this, you create a new DatabaseUtility object, and then use it to your hearts content.
    Cheers,
    evnafets

  • Calling a static method when starting the server???

    Hi,
    i wanted to call a static method of a java class,
    whenever i start the server.
    plz give some input on this.
    thanks and regards
    siva

    Siva -- Can you be more specific as to the problem you are trying to solve (why do you want to call this static method,.)
    The reason I ask is that there are some ways to make this happen but they may have limitations
    that won't work for you. For instance, you can create a servlet that calls your class' static method and then make the
    servlet be loaded on startup.
    Thanks -- Jeff

Maybe you are looking for

  • IF-statement in Personas that is checking if control is inactive?

    Hi, I have this simple script in screen personas that is clicking the option: "Attachment list". Everything is working great if there is attachments. If there are no attachments the option is "inactive" or "greyed out". This will result in a script e

  • ITunes Producer ERROR-ITMS-6010

    Trying to use iTunes Producer to upload a new album. I'm getting: ERROR-ITMS-6010 "Adding bonus material to this playlist is not allowed" at Album/Tracks/BonusMaterial... Does anybody know what to do? Thanks...

  • How to report with different time zone dynamically based on user's account?

    Hello I am wondering is there a way to change the report's date & time data based on user's locale setting in OBIEE? Let's say the user log in to OBIEE with eastern time zone setting. The data that's in the database is storing a transaction of $400 a

  • How to remove interlacing Premiere is adding on export?

    I am using a Mac, and the first CC. Processor: 2.66 GHz Intel Core 2 Duo Memory: GB 1067 MHz DDR3 Graphics: NVIDIA GeForce 9400 256 MB When ever I export video, it comes out interlaced. Doesn't matter what size or codec. I also followed the steps her

  • Assembly and C

    I'm trying to learn a little bit about assembly and such, so I made a multi-language program to figure out a little bit. It's very simplistic, but it accomplished what I want for the most part. Here is what I wrote mix_asm.asm: section .data new_line