Are anonymous classes reentrant and multi-thread safe?

Consider the following code. Please let me know how does this code behave wrt to reentrancy and MT. My main confusion is with the "static" keyword.
Appreciate any inputs. Thanks in advance.
public abstract class AnAbstract {
   public abstract int abstractFoo();
   public static AnAbstract AnAbstractImpl = new AnAbstract() {
      public int abstractFoo() {
         //do stuff here....
         return 0;
   public static void main(String [] args) {
      System.out.println(AnAbstract.AnAbstractImpl.abstractFoo());
}

static has nothing to do with threading.
Nor is there anything special about anonymous classes.
As implemented the class is safe.
However, given that the class is going to do more than the code that you posted the actual implementation might not be safe.

Similar Messages

  • SSRS - Is there a multi thread safe way of displaying information from a DataSet in a Report Header?

     In order to dynamically display data in the Report Header based in the current record of the Dataset, we started using Shared Variables, we initially used ReportItems!SomeTextbox.Value, but we noticed that when SomeTextbox was not rendered in the body
    (usually because a comment section grow to occupy most of the page if not more than one page), then the ReportItem printed a blank/null value.
    So, a method was defined in the Code section of the report that would set the value to the shared variable:
    public shared Params as String
    public shared Function SetValues(Param as String ) as String
    Params = Param
    Return Params 
    End Function
    Which would be called in the detail section of the tablix, then in the header a textbox would hold the following expression:
    =Code.Params
    This worked beautifully since, it now didn't mattered that the body section didn't had the SetValues call, the variable persited and the Header displayed the correct value. Our problem now is that when the report is being called in different threads with
    different data, the variable being shared/static gets modified by all the reports being run at the same time. 
    So far I've tried several things:
    - The variables need to be shared, otherwise the value set in the Body can't be seen by the header.
    - Using Hashtables behaves exactly like the ReportItem option.
    - Using a C# DLL with non static variables to take care of this, didn't work because apparently when the DLL is being called by the Body generates a different instance of the DLL than when it's called from the header.
    So is there a way to deal with this issue in a multi thread safe way?
    Thanks in advance!
     

    Hi Angel,
    Per my understanding that you want to dynamic display the group data in the report header, you have set page break based on the group, so when click to the next page, the report hearder will change according to the value in the group, when you are using
    the shared variables you got the multiple thread safe problem, right?
    I have tested on my local environment and can reproduce the issue, according to the multiple safe problem the better way is to use the harshtable behaves in the custom code,  you have mentioned that you have tryied touse the harshtable but finally got
    the same result as using the ReportItem!TextBox.Value, the problem can be cuased by the logic of the code that not works fine.
    Please reference to the custom code below which works fine and can get all the expect value display on every page:
    Shared ht As System.Collections.Hashtable = New System.Collections.Hashtable
    Public Function SetGroupHeader( ByVal group As Object _
    ,ByRef groupName As String _
    ,ByRef userID As String) As String
    Dim key As String = groupName & userID
    If Not group Is Nothing Then
    Dim g As String = CType(group, String)
    If Not (ht.ContainsKey(key)) Then
    ' must be the first pass so set the current group to group
    ht.Add(key, g)
    Else
    If Not (ht(key).Equals(g)) Then
    ht(key) = g
    End If
    End If
    End If
    Return ht(key)
    End Function
    Using this exprssion in the textbox of the reportheader:
    =Code.SetGroupHeader(ReportItems!Language.Value,"GroupName", User!UserID)
    Links belowe about the hashtable and the mutiple threads safe problem for your reference:
    http://stackoverflow.com/questions/2067537/ssrs-code-shared-variables-and-simultaneous-report-execution
    http://sqlserverbiblog.wordpress.com/2011/10/10/using-custom-code-functions-in-reporting-services-reports/
    If you still have any problem, please feel free to ask.
    Regards
    Vicky Liu

  • Memory leaks and multi threading issues in managed client.

    In our company we use a lot of Oracle, and after the release of the managed provider we migrated all applications to it. First the  things were very impressive : the new client was faster, but after some days applications that uses 100MB with old client goes to 1GB and up. The memory is not the only issue, we use a lot of multi threading, and we experience connection drops and not disposal, after 1 days working one of the application had over 100 sessions on the server. I think there is something wrong with connection pool and multi threading.
    Is someone experience same problems.
    Yesterday we went back with unmanaged provider. Now things are back to normal.

    connection drops: did you try to use "Validate Connection=true" parameter in your connection string?
    the new client was faster: are you sure with this statement? Even in 64bit environment? I got quite serious performance problems when running application under 64bit process: https://forums.oracle.com/thread/2595323

  • Enterprise User and Multi Thread Server

    Hi,
    We are going to build a system which uses a configuration:
    10g2
    Enterprise User
    Multi Thread Server
    Client apps accesses db over JDBC/SSL
    Could some please share experience about issues regarding
    using Enterprise User and Multi Thread Server ?
    Is MTS transparant for Enterprise User authentication ?
    Regards,
    Cezary

    If you build simpserv with -t, and set MIN and MAXDISPATCHTHREADS, you
    should have an example of a multithreaded server.
         Scott
    Johan Philippe wrote:
    >
    We have been going to the documentation on multi-threading and contexting in servers
    on Tuxedo 7.1.
    And the impression so far is that apart from the function definitions there is
    not much information around.
    Didn't even find a simple example of a multi-threaded server in the Bea refs yet.
    Does anyone know/have such an example?
    And is anyone using multi-contexting in a server, because the limitation that
    only server-dispatched
    thread get a context puts quite a limitation on its usefullness.

  • Is ABAP multi-threading safe?

    When implementing the Singleton design pattern in Java, we must use keyword <b>synchronized</b> with <b>getInstance()</b> method to ensure multi-threading safety, so that we can get the one and only instance.
        What shall I do in ABAP? or just leave it alone?  Would you help me find a example?
        thanks and regards,
      Davin,WANG

    Hi Davin,
    I do not understand fully what you are going to do in ABAP terms so I hope my comment will be of any value.
    Multithreading may be achieved in ABAB by calling a function with the addition STARTING NEW TASK IN GROUP.... See my sample program for <a href="https://wiki.sdn.sap.com/wiki/display/Snippets/Easilyimplementparallelprocessinginonlineandbatchprocessing">Easily implement parallel processing in online and batch processing</a>
    The second question may be solved by help of SAP lock concept. This is used primarily to secure a consistent database by not allowing two processes to change data at the same time. Chose a lock object of your choice and set at start of first instance. At end, remove the lock. Before creating the second instance, try so set the same lock. If you get a foreign lock error, you know the process is running.
    See documentation on lock objects on how to lock/unlock.
    Regards,
    Clemens
    Hope your internet connection is broken no longer so you can read this.

  • Aggregate Storage And Multi-Threading/Multi-Core Systems

    Please pardon if this question has been asked before, but the Forum search is not returning any relevant results.
    We are in the process of purchasing hardware for an 11.1.2 Essbase environment. We are going 64-bit, on Windows 2008, with either 32 GB or 64 GB of system RAM. The debate we are having is the number of CPUs and cores per CPU. We have not built any ASO databases as of yet, but we plan to launch a major BSO to ASO conversion project once 11.1.2 is off the ground here.
    Historically, with BSO, we did not see performance improvements significant enough to justify the cost of additional CPUs when we ran calcs on multi-CPU systems vs. single or dual CPU systems, even when the settings and design should have taken the most advantage of BSO's multi-threading capabilities. However, it would seem that ASO's design may be able to make better use of multi-core systems.
    I know that there are a lot of factors behind any system's performance, but in general, is ASO in 11.1.2 written well enough to make it worthwhile to consider, say, a four CPU, total 16 core system vs. a 2 CPU, total four core system?

    Grand central dispatch - infancy, not really doing its job, and I don't think apps have to be specifically written for HT, but they do have to not do things that they use to - prevent threads from going to sleep! or be parked.
    high usage is not necessarily high efficiency. often the opposite.
    Windows 7 seems to be optimized for multi-core thanks to a lot of reworking. Intel wants and knows it isn't possible to hand code, that the hardware has to be smarter, too. But the OS has a job, and right now I don't think it does it properly. Or handle memory.
    Gulftown's 12MB cache will help, and over all should be 20% more efficient doing its work.
    With dual processors, and it doesn't look like there are two quick path bridges, data shuffling has led to memory thrashing. Use to be page thrashing with not enough memory. Then core thrashing but having the cores, but not integrated (2008 is often touted as being greatest design so far, but it was FOUR dual-cores, 2009 was the first with a processor that really was new design and (native) 4-core.
    One core should be owned by the OS so it is always available for its own work and housekeeping.
    The iTunes audio bug last year showed how damaging and not to implement code and how a thread could usurp processing and add a high cpu temperature while basically doing nothing, sort of a denial of service attack on the processor - those 80*C temps people had.
    All those new technology features under development and not like OpenCL, GCD and even OpenGL are tested, mature but rather 1.0 foundation for the future. A year ahead of readiness.

  • Indesign and multi threaded cpu support??????????

    When the indesign will finally support multi-core processors?????? It is tragic that adobe dont have any support for multi-core cpu and that this products cost thousends $$$$$!!!!!!!!!!!!!!! Only premiere and some photoshop function support multi-core cpu.

    If you are good freelancer you can get money spent on CS back in a month. So I would not call this software expensive. What concerns multi threaded cpu support I believe that programming tools as well as operating systems need to evolve. I am sure that we will get better support in this matter in close future.

  • A problem about event-driven and multi-thread ( maybe?)

    I am thinking of doing a piece of small software. I am going to write a server, storing some dynamic information. and each client (surely in different threads) has a JList, which is supposed to update itself with server, such as adding an item, etc.
    a straightforward example is an IM software, each client stores a list of online buddies, and if a new client logs in, many other clients have to update the buddies list.
    What is a good approach of doing that? I am thinking of adding a public method, addItem() into the thread handler, which adds a new item into the JList. but is it a good design to have a public method other than "run()" in the thread handler?
    Or do I have to define a new event of new item needed to be added?
    Thanks.

    Actually I am just asking for how to design a good communication between the server and the client...
    so just as a client A logging in, the server knows that the client A has logged in, and A,B are friends, B's friend lists should be updated, which means adding A to that list. so I am thinking have a addItem() method in the thread handler of B, so I can call ThreadHandlerB.addItem( A ) in the code of the server, since server knows that A has logged in.
    or is there any good approach? And most importantly, is it a safe way to have a public method in the thread handler?
    Thanks so much!

  • Mutli-Core and Multi-Thread Clusters?

    I have created Quick-Clusters in Compressor, but whenever I try to encode using one, it fails.
    Not sure what to do here.

    There are a few simple things that I would start with.  I was able to get Compressor 4 working on all my cores and even able to "oversubscribe" if you will.  I was even able to do it with Compressor 3.5 installed still.  Not meaning to intentially, but when going to the app store and purchasing Compressor, you dont have much of an option to move it to another drive or partition with ease. 
    Start by installing and restarting your computer. Not sure if this is neccasary, but it seemed to clear out a few processes that were running. 
    Second, go to preferences and go into apple qmaster.  Stop sharing all services.  You wont be using this anymore.
    Launch Compressor 4.  Go to apple Qmaster within Compressor 4.  Click on Share this computer.  Click on quickcluster.  You can then click the next two options for renduring and compressor and then you can control the number of instances started by clicking on the options tab.
    Once you import the video and add setting click submit. Select the name of your quickcluster and share monitor will pop up.  The rest is history, just like old days with 3.5. 
    Hope that helps.  Its a simple process it just took a few minutes to figure out.  The documentation for setting up a quickcluster really sucked. 
    Oh, once downloading and starting up Compressor 4 for the first time, you should go get updates, looks like there was a patch for some of the video formats.
    Cant promise it will fix everything but I couldnt even find a simple setup doc or thread.

  • What are abstract classes/methods and what are they for?

    Hi,
    I've just heard about abstract classes and methods and I'm just wondering what exactly they're used for, and why are they there for the Graphics class for example?
    Cheers.

    raggy wrote:
    bastones_ wrote:
    Hi,
    I've just heard about abstract classes and methods and I'm just wondering what exactly they're used for, and why are they there for the Graphics class for example?
    Cheers.Hey bro, I'll try to solve your problemYou have to know two important concepts for this part. 1 is Abstract classes and the other is Interface classes. Depends on the nature of the project, you need to set certain level of standards and rules that the other developers must follow. This is where Abstract classes and Interface classes come into picture.
    Abstract classes are usually used on small time projects, where it can have code implementation like general classes and also declare Abstract methods (empty methods that require implementation from the sub-classes).Wrong, they are used equally among big and small projects alike.
    Here are the rules of an Abstract class and method:
    1. Abstract classes cannot be instantiatedRight.
    2. Abstract class can extend an abstract class and implement several interface classesRight, but the same is true for non-abstract classes, so nothing special here.
    3. Abstract class cannot extend a general class or an interfaceWrong. Abstract classes can extend non-abstract ones. Best example: Object is non-abstract. How would you write an abstract class that doesn't extend Object (directly or indirectly)?
    4. If a class contains Abstract method, the class has to be declared Abstract classRight.
    5. An Abstract class may or may not contain an Abstract methodRight, and an important point to realize. A class need not have abstract methods to be an abstract class, although usually it will.
    6. Abstract method should not have any code implementations, the sub-classes must override it (sub-class must give the code implementations). An abstract method must not have any implementation code code. It's more than a suggestion.
    7. If a sub-class of an Abstract class does not override the Abstract methods of its super-class, than the sub-class should be declared Abstract also.This follows from point 4.
    9. Abstract classes can only be declared with public and default access modifiers.That's the same for abstract and non-abstract classes.

  • Thread-safe dlls: re-entrant

    Hi!
    I've been trying to research on multi-threaded dlls w/ jni, & it seems every native method HAS TO BE synchronized. Unfortunately, my reqs call for native methods that are NOT ENTIRELY synchronized. The option I came across was TLS, although actually I was looking for better options. Then I found Roedy Green's advice that TLS was not even an option!
    Help! It seems that if native methods are NOT synchronized, any variable will be prone to being overwritten when multiple java objects call the method? My assumption is that native code is not translated into unique object space for each object since a dll is involved.
    TIA,
    Reggie

    Thanks again for your patience! Let me restate my
    problem: I need several instances of the same class
    running the same JNI code, w/c of course reside in a
    dll. I want my classes to be thread-safe, so I thought
    of using Thread-Local-Storage. Unfortunately, I found
    references on the web that JNI does not work w/ TLS.
    Neither can I simply "synchronized" the whole native
    method from java. Do I have other options?
    I still must not be precise enough.
    For java and C++ there are two types of variables (created various ways): single thread visible and multi-thread visible. For example:
    - Java/C++ static class variable (multi-thread visible)
    - Java/C++ member class variable (single thread visible)
    - Java/C++ local (method) variable (single thread visible)
    There are three interfaces to the variables:
    -Java only.
    -C++ only.
    -Java variables accessed in a JNI method.
    So there are six possible cases.
    1. Java only, single thread visible. Absolutely nothing you do will make these visible to other threads so there is never any point to synchronization
    2. C++ only, single thread visible. Again you can't see these in other threads so it doesn't matter.
    3. Java only, multi-thread visible. You have to synchronize these variables using java methods.
    4. C++ only, multi-thread visible. You have to synchronize these variable using C++ methods. Keep in mind that if you got to this point using java then you are still in a C++ thread - the jvm created it. The only problematic aspect is if the OS supports multiple thread models (Windows doesn't.) Then you have to determine the model to use the correct locking mechanism.
    5. JNI, single thread visible. Again you can't see these in other threads so it doesn't matter.
    6. JNI, multi-thread visible. In this case you need to create a java synchronization method in your C++ code. For example if you want to access a static variable of a java class in C++ you would have to synchronize it. In this case I would strongly recommend writing a java method and calling that instead. The synchronization code will be much easier to understand in java and it will significantly simplify the C++ code.
    Now the above cases should cover everything. If not you need to specifically tell me what is missing.

  • Method Scope variables controls Multi-Threading !

    Hye there Experts !
    First, let me thank you all for such a brain-stuff sharing around; feel nice to be a part here.
    While browsing through the below article, found something confusing...kindly clarify.
    http://www.javaworld.com/javaworld/jw-07-2004/jw-0712-threadsafe.html?page=1
    Extract from the above discussion I understand :
    when a variable is moved to method scope instead of instance scope, synchronization is achieved.
    How is this true for servlets ???
    Method scope variables are available only during method call I think...here, since this is a servlet, there will be only one instance and if many (lets say 10) requests hits this servlet object, all these threads will read same counter as all of them enter into this only one method of this object,
    so...this should be still not thread safe I guess.
    I didn't want to execute and see results of this code, but I am trying to understand the key at first.
    Please guide me before brain blows... :-)
    Would also appreciate any references that really says true things about
    'synchronization for enterprize (handle huge requests) web apps - technques for servlets and any other stuff'
    Thanks again guys, have a wonderful time.

    feel nice to be a part here.Welcome to the mad-house ;-)
    Method scope variables are available only during method callWARNING: I'm no guru, so this may be misleading or just plain wrong.. but as I understand it:
    Yep a "local" variable exists only the context of the execution of it's containing method... so a local variable is implicitly bound to the thread that created it (by invoking the method in which the local is declared)... a local variable can't be accessed directly by another thread simply because the other thread has no access-path to the variable (you can't expose a local through getters & setters)... hence locals are thread safe.
    The important bit is that it's the thread which "owns" the local variable... not the declaring method... if the method is executed concurrently by two threads, each thread will have its own private copy of all the local variables.
    One other question though: are locals in static methods still thread safe? I'm not sure.
    package forums;
    class NonfinalLocalVariableInThreadTest
      public static void main(String[] args) {
        try {
          new Thread(new Runnable() {
            public void run() {
              System.out.println(args[0]);
          }).start();
        } catch (Exception e) {
          e.printStackTrace();
    compiler error
    C:\Java\home\src\forums>"C:\Program Files\Java\jdk1.6.0_07\bin\javac.exe" -Xlint -d c:\java\home\classes -cp c:\java\home\src;.;c:\java\home\classes c:\java\home\src\forums\NonfinalLocalVariableInThreadTest.java
    C:\Java\home\src\forums\NonfinalLocalVariableInThreadTest.java:9: local variable args is accessed from within inner class; needs to be declared final
              System.out.println(args[0]);
                                 ^
    1 error
    Output completed (0 sec consumed)

  • Clarification of the handle/body idiom in multi threaded applications

    Hello
    As some DBXML classes use the handle-body idiom (handle/body idiom in some docs), could someone please clarify the consequences of that in a multi threaded application like a web container?
    For 100% Java people, like me, this is known in the Java world as 'programming towards interfaces', or as the Bridge pattern; which is seen as good practice.
    Let's take an example. The class XmlQueryContext is not thread safe, but it has a copy constructor. Imagine that your web application has one XmlQueryContext, that we never use in a query, but that we prepare only to be copied in new threads. Is it thus safe to instantiate various new XmlQueryContexts using that copy constructor in various new threads and use them simultaneously?
    Thank you
    Koen
    PS What I am really asking here is if somebody could please translate the following to Java parlé:
    A copy constructor is provided for this class. The class is implemented using a handle-body idiom. When a handle is copied both handles maintain a reference to the same body.

    As a Java user you do not have to worry about how the C++ copy constructors behave. In the Java API if a copy constructor exists for the object, then the copy constructor will copy all of the original object's data into a new object (XmlContainer is the one exception to this rule, generally one should not use that copy constructor at all). So in short, what you plan to do will work.
    Lauren Foutz

  • Java Security Manager in Multi-threaded application

    I am writing a multi-threaded application listening (TCP and UDP) to several ports. To help implement certain security features (eg. refusing connections from certain ip address), I'm using the java.lang.SecurityManager (by subclassing it). I am having a few problems and queries and am hoping someone here can help me.
    1. As all the threads are calling the checkAccept(host, port) method. Is there a way to know which thread is currently accessing the security manager? For example if host A were to make 2 connections to the application, one to thread 1 (say listening to port 5001) and the other to to thread 2 (say listening to port 5002). I intend to refuse the connection to thread 2 but there is not way of differentiating the 2 connections since they are from the same host and there isnt any way of knowing their port number.
    2. Are calls to the Security Manager thread safe?
    I have been having this problem for a long time, would appreciate if someone can help point me to the right direction. cheers.

    1. As all the threads are calling the
    checkAccept(host, port) method. Is there a way to
    know which thread is currently accessing the security
    manager?Just use Thread.currentThread(). As specified in the Javadoc for e.g. SecurityManager.checkAccept().
    2. Are calls to the Security Manager thread safe? No.

  • Multi threading under single file channel

    Hi,
      We have File-Proxy scenario .
    We are using fCC sender channel and using
    recordset sequence as varaibale
    recordsets per message was 250.
    When large size file like 2GB was processed, PI is taking 45-50 min to process the file and from proxy end its taking 8 hrs to process this file.
    we are using one channel and 250 recordsets per message by chunking file and process to target. We are following EOIO for sequence for these chunk files.
    with this approach in PI target system proxy is taking huge time to process.
    experts suggested using multi threading and multiple channels are the ideal solution for this issue.
    am expecting with multiple channels and multi threading  will cause issue for receiver proxy  because of more objects and current approach is fine.
    Please suggest any other alternatives we can acheive in PI with respect to this issue?
    Note: I checked blog for file chunk option under Adv parameters and I cant use that here as FCC and Mapping is there .
    Rgds,
    aman

    Hi Aman,
    We had file to proxy interface and the XML payload of the proxy was around 400mb...to reduce the time taken in PI in mapping step we reduced the XML payload of the proxy by cutting the XML tagnames.
    for example an xml field <firstname>Anand</firstname> was converted to <f>Anand</f>
    with this we were able to achieve about 40-50% reduction in XML payload the file and a good improvement in the time taken by PI mapping to process the file.
    Hope it helps,
    Thanks,
    Anand

Maybe you are looking for

  • Looking for a Better Search Solution

    One of my company's products has a large number of configuration options that we purposefully don't include in the regular online help. We have been providing a separate PDF of the settings, but we are now switching to an online help format (a separa

  • GR document print out

    Dear All, The user does goods receipt and the print does not comes automatically. It happens only in case of non stock items. Though I am not sure if there is any link with it but they have to go to MB02, then go to messages, put output type as WE03(

  • How do I sort a bookmark into a folder initially when I want to bookmark a page?

    In firefox 4/5 you could right click the page and select "Bookmark this page" and a dialog box would popup and ask you where you want to put the bookmark. On firefox 6, when I right click and select "bookmark this page" the dialog box does not come u

  • Report Background Engine - How do I determine where it is located

    We have several servers running Oracle Forms and Reports. The person who set up the applications I supported has left and no one can tell me which Reports Background engine/server my reports are running on. How can I determine it and tell them. Thank

  • Error message while saving cryrstal report

    Hi Experts, following error message occured while safing a crystalo report: "an error occured while safing and/or publish. The return code 503 was returned from the server. Report ID entered is invalid" in the pop-up "Save to BW options" I have choos