Sharing variable across Threads created by ThreadFactory

Hi,
I am initializing an ExecutorService as:
static ExecutorService service =
Executors.newFixedThreadPool(16, new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
Thread t = new Thread(r);
t.setContextClassLoader("<<My_Class_Loader");
return t;
Now, I have to initialize a service that should be initialized only once that all the Callables submitted to this ExecutorService can use. The variable needed to be shared across the Threads must have "My_Class_Loader" as its ContextClassLoader. How can I do that? Thanks in advance.

Something like this:
Thread t = new MyThread(r, ccl); // ccl = your context class loader
public class MyThread extends Thread
  private MyVariable myVariable;
  public MyThread(Runnable r, ClassLoader ccl)
    super(r);
    this.setContextClassLoader(ccl);
    myVariable = ...; // your class loader stuff
  public MyVariable getMyVariable()
    return myVariable;
// ... then runnables can go:
((MyThread)Thread.currentThread()).getMyVariable();

Similar Messages

  • How do I setup shared variables between executables created in sepparate projects

    Hello,
    I have several sepparate projects with their own respective executable files and I would like to be able for these executable files to all share the same variable (one program controls the value of the variable, while the others read from it).
    I got this setup to work on my personal computer (by being able to access variable manager, etc), but I need to deploy these executables on different computers that don't have the labview development program. What steps do I need to do in order for me to be able to put these executables on any computer (I'm assuming I need to setup a path for the shared variable that is always in the same folder, etc)
    Thanks
    Vlad
    Solved!
    Go to Solution.

    Hi Vlad,
    I think this article may answer some of your questions regarding shared variables in deployed applications.
    http://zone.ni.com/devzone/cda/tut/p/id/9900
    It sounds like you already have your executables built, but this article may answer some questions about deploying them to other machines.
    http://zone.ni.com/devzone/cda/tut/p/id/3303
    Jeff S.
    National Instruments

  • 'Thread-shared' variable across JSPs

    Hi folks,
    I'd really appreciate some help with something - I'd like to have a variable that each JSP on my site can access, so if, say, 5 people are on my site at a given time, and one of them changes it, the changes will be seen by the other visitors.
    For example, it's an online game andthe current maximum score is always shown at the top right, on each page refresh the score of the player who is currently winning is shown...
    I understand that your run-of-the-mill variable on a JSP page is a per-page variable... how can I create a.... er... not-per-page variable? (As you can tell my lack of relevant terminology has somewhat hampered my googling so far!) :os :oD

    Thannks bbaldino - I've had a bit of a read about Application Scope variables, and they do seem to do what I am after, I think.... hopefully Uncle Google will work with me on the rest!
    Thanks again!

  • How do I access variables across threads.

    I am calling a custom callback from TestStand which is kicked off by the user clicking on a User Interface button.   I am running in Batch Mode and would like to get the index of the execution the user is viewing at the time he/she clicked on the button.   I have tried it seems like every RunState variable and TestStand API with no success.  How are you supposed to get information from parallel threads in TestStand?

    TestStand Already provides a Terminate function.  This is what you get when you Left mouse click on the TestSocket Execution Icon them immediately right-mouse click and select Terminate.   I tie into this fuctionality with my customized Operator Interface in C# I put a call back on the Terminate button click. 
    I would like for this event to notify me on the specific TestSocket Thread that is being executed for some critical things to take place before the Thread is actually terminated.
    This is the events I would like to take place:
    1) User runs test sequence in batch mode.
    2) Thread run normally.
    3) User decides he/she wishes to stop testing on 1 or all UUTs.
    4) User Clicks on either Terminate single or Terminate all.
    5) Software point of view a Callback occurs allowing for critical processing to occur before actual thread is stopped.
    6) Thread or Threads is/are stopped.
    All this takes place in TestStand 4.0 now except for step 5.   I customized the Operators User Interface to do an execution callback into the model before the thread is fully terminated.  This call works asynchronously as desired.  It calls the execution entry point into my BatchModel as desired.  If I present a popup asking for the TestSocket he/she is wishing to terminate then I can do this processing to the UUT as desired.   However is his/her response does not agree with what was selected on the Operator Interface GUI then my stuff runs on 1 TestSocket and yet another TestSocket is actually stopped.

  • Can volatile variable be called as static variable for threads?

    I am trying to understand volatile variable, and it's uses. I was thinking of using it to make it shared variable between threads, but not between object instances.
    public class VolatileExample extends Thread {
      volatile int x = 1;
      public void f() {
           x++;
           System.out.println(Integer.toString(x));
        public void run() {
              for(int i = 0; i<20;i++){
                   f();
                   try { Thread.sleep(500); } catch(InterruptedException e) {}
        }now, if I create two threads in main method of the same VolatileExample class, say T1 and T2, how many times would volatile int x be instanciated? would there be just one copy of volatile int x created, no matter howmany threads I create?

    WHICH REMINDS ME: YOU DIDN'T ANSWER MY QUESTION AS TO
    WHETHER YOU UNDERSTAND THREADS' LOCAL COPIES OF
    VARIABLES VS. THE MAIN MEM COPYIn my understanding,
    local copies means each thread gets their own copy of a variable and they play with it separately. changing this variable in one thread does not chage value for another thread.
    main mem copy is the one accessed by all the threads. If one thread changes this value, it is reflected to all other threads using this variable.
    right?
    I tried using voaltile variable as shared variable like this:
    import java.io.*;
    public class VolatileIncrement {
      private int x = 1;
      public void f() {
           x++;
           System.out.println(Integer.toString(x));
      public String toString() { return Integer.toString(x); }
      class MakeThread extends Thread{
           public MakeThread(){
                System.out.println("starting MakeThread thread");
         public void run() {
              for(int i = 0; i<20;i++){
                   f();
                   try { Thread.sleep(500); } catch(InterruptedException e) {}
      public void createT() {
         Thread T2 = new MakeThread();
              T2.start();
         Thread T1 = new MakeThread();
              T1.start();
    }and created another class:
    import java.io.*;
    class TestVolatile
         public static void main(String[] args)
              VolatileIncrement vi = new VolatileIncrement();
              System.out.println("creating threads now...");
              vi.createT();
              System.out.println("Done Testing!!");
    }can this be called as correctly using non-static volatile variable as shared data?

  • RT Network Shared Variable and Visa Serial Instr class

    Hi,
    I'm using Labview 2009 SP1 with the RT module. I've had no problems creating a RT Target application and a Host PC application which are interconnected using Network Shared Variables, until I came to the COM ports fitted to the RT Target (PXI Embedded Controller and 2 x 4 port COM cards).
    I can configure and use the COM ports in the RT Target application providing I use constants to define which COM port to use, i.e. VISA OPEN function accepts hardcoded "COM2" , (VISA Serial Instr class).
    But I want to pass the COM Port resource name from my host application. 
    Is there a suitable Network Shared Variable I can create ? or how do I change the string value (COM Port name) of the VISA Serial Instr class variable in the RT Target application ?
    thanks,
    Gary.

    Hi there Gary,
    Thanks fot the post. I think I have found something that may be if use to yourself.
    http://labviewwiki.org/Functional_global_variable
    This is the functional global variable.
    Take a look at it and let me know what you think!
    Many thanks,
    Liam A.
    National Instruments
    Applications Engineer

  • NI Visa - Shared Variable Engine

    Hi,
    I am using labview Shared Variable Engine to create variables on my workstation and bind them to variables on my server.
    I have labview 8.2 installed on my workstation and labview 8.5 installed on my server.
    The communication between them worked perfectly and I was able to use the variables created in the workstation.
    In my application I need yo use NI visa to take serial input. So I installed the NI Visa on my workstation and the NI visa worked.
    However, the Server was not able to see the variables I have created in my workstation.
    Does this mean that NI visa do not work in parallel with the Shared Variable Engine, or does the NI visa change some of the settings parameters that would stop the Shared Variable Engine from working properly.
    Thanks in Advance

    This information helps me get a better idea of what you are doing, but I need much more information in order to help pinpoint what is happening in your application. You should absolutely be able to use VISA as well as the Shared Variables concurrently. What is the device that you are using for data acquisition? I'll need the model of the device. What kind of data are you acquiring? How are you using VISA to communicate with your instrument?
    One other item is to look in the distributed system manager to see if your shared variables are actually getting updated
    Any code you could post here would help as well.
    National Instruments
    Applications Engineer

  • Binding Shared Variable to Source

    Dear all,
    I'm currently working on a project that requires the use of shared variables. The shared variables will be network published and programmatically created using properties nodes. However I encounter one error and one problem in the process of doing so.
    1) I programmatically bind the shared variable directly to the fieldpoint channel (data item) by writing the URL \\10.0.0.1\FP\1AIO\00 when i create the shared variable. The shared variable can be created successfully but when i deploy it, it generates an error which seems to tell me "it is out of range". Can anyone help me to rectify this problem?
    2) The 2nd question will be, as my fieldpoint is connected to a DHCP server. At the start when i create the shared variable programmatically, i could bind the shared variable directly to the data item by writing the URL to its property. However, during the process of deployment, the dynamic IP address assigned to my fieldpoint may change . How can I ensure that the shared variable continue to bind to the right fieldpoint channels respectively? even though the IP address changes?
    - Or is there any method that I could view all the network data items in a table? a list? or an array? so that I can link them to the URL.
    I tried using the data socket URL.vi, I can only select the data item one by one.. this will be tedious for 100 or 200 I/O points..
    Will greatly appreciate for any advice and help. Thanks in advance.

    Try this.
    Give your fieldpoint controller a computer name through MAX.  Then instead of referencing it by 10.0.0.1 in the URL's of the shared variables reference it by computer name.  So  \\MyFPmachine\FP\1AIO\00 instead of  \\10.0.0.1\FP\1AIO\00.
    Dynamic IP's can definitely cause headaches, and it would be best to use static IP's if possible, but doing this method should help.  It seemed to work for me.  I found when you browse for the channel in LV, it wants to give it the IP address by default, but it was possible to edit the string and paste in the computer name.
    Message Edited by Ravens Fan on 01-10-2007 11:01 AM

  • Shared Variable Properties and DSC

    Is there a way to assign engineering units to a shared variable as a
    configuration parameter?  This should be on the "Scaling" page of
    the shared variable properties.  It seems this is a logical and
    convenient place to track units.  Assigning units programmatically
    using the Scaling:Units property is awkward (to say the least).
    On similar lines, why aren't shared variable properties automatically
    saved to the DSC historical database?  Every trace should have a
    set of information that exposes ALL the shared variable properties that
    created it.  Take something like engineering units for
    example:  then you would know what kind of historical trace you
    are looking at!  This seems so basic I can't imagine why it was
    missed.
    Unless I missed something -- please enlighten me.
    Regards,
    David Moerman
    TruView Technology Integration Ltd.

    Hello David,
    You are correct in that the units property is not exposed on the
    Scaling page of hte Shared Variable properties dialog, and it sounds
    like you are already well aware of the existing method to access this
    property through the property node interface.  As you have also
    discovered, the Citadel database that we use with DSC does not have a
    built-in provision for storing metadata about the shared variable from
    which a trace originates.  You can emulate this with, for example, an
    array of strings which is also logged to the database, with each string
    containing the metadata for a particular trace. 
    Since it seems like having these features would benefit you, I
    encourage you to let our DSC development group know your needs by
    filling out product feedback, accessible on our site at
    http://www.ni.com/contact   .  This will send a feature request
    directly to the appropriate R & D group, who reads and evaluates
    every suggestion made.  This is your most direct way to let us know
    what features would best meet your needs.
    Cheers,
    Matt Pollock
    National Instruments

  • Shared variables location

       I'm starting a fairly large project and wanted to organize it properly.  When I needed a shared variable, I first created a new library.  I was able to specify the location of this library in a sub-directory within my projects file structure.   Then I made some shared variables (single process).  After saving the project, the shared variable files appeared in the main project directory, at the same level as the .lvproj file, not in the subdirectory where the library was created.
       Any tips for orginizing shared variables?
    Thanks,
        Dave
    David Thomson Original Code Consulting
    www.originalcode.com
    National Instruments Alliance Program Member
    Certified LabVIEW Architect
    There are 10 kinds of people: those who understand binary, and those who don't.

       Thanks for the reply.  Unfortunately, the problem remains:
       I first create the library explicitely, before creating any variables.  I saved the library to a subdirectory.  Then I create variables.  When the variables are instantiated within a VI, at some point LabVIEW automatically creates vi files on the disk corresponding to these variables.  These VI files were placed in the main directory with the project file, not in the subdirectory where I put the library.  This is surprising to me and I would think this is a bug.
        My solution at this point was to create a "Project" subdirectory.  I put the .lvproj and the .lvlib file in that subdirectory and now the shared variable vis appear there as well.  This is a kludge.
       My main question at this point is:  can you specify where these shared variable VI's get created and stored?  I suspect that you could edit the .lvproj file or other xml files to change the share variable paths, but that is inappropriately difficult.  I tried just moving the files to where I wanted them, but then the variables don't load.  I managed to reload them, but at some point, they recreated themselves in the original location.
       At a minimum, the shared variable VIs should create themselves in the same directory as the .lvlib file that they belong to.  At least you can specify where the .lvlib file lives.
    Regards,
       Dave
    David Thomson Original Code Consulting
    www.originalcode.com
    National Instruments Alliance Program Member
    Certified LabVIEW Architect
    There are 10 kinds of people: those who understand binary, and those who don't.

  • LABVIEW 2012 - shared variable error during programming of NI CRIO 9023 and TPC 2212

    HELLO,
    i am using CRIO 9023 with TPC 2212 and LV 2012. I want to develop a stand alone app which has a front panel on TPC. at first i am building a simple app with two controls variables, one is a sliding bar on TPC Vi and the other one is the while loop  variable "i" on CRIO VI. i used  shared variables.
    first i creat shared variable on CRIO side and access this on TPC Vi. I COMPILE both Vi,s and they are working fine. But when i created the slide bar control in TPC VI, compiled and deploy the TPC Vi, it get deployed in TPC. But when i  start compiling the CRIO VI an error mesage occured as follows;
    I have tried every option to best of my understanding like formating crio then installing all softwares including Network variable engine etc. i also go in properties of the executable file of TPC Vi and go in properties-shared variable- then check the "deploy variable in application" option . below is image displayed.
    I am in despirate need for solving this problem as i have to develop the final app for testing soon. can some one help me regrarding this.
    REGARDS

    I would not recommend using shared variable engine.  It is supposed to make things easier, but in fact, you will spend more time troubleshooting why it is not working than you will actually coding an alternative solution.
    Try the Simple TCP Messaging instead.
    http://zone.ni.com/devzone/cda/epd/p/id/2739
    Machine Vision, Robotics, Embedded Systems, Surveillance
    www.movimed.com - Custom Imaging Solutions

  • Sharing User Defined Variables across projects

    Hi,
    I'm wondering if it's possible to share User Defined Variables across projects. What I have in mind is that I would like to have my User Defined Variables configured in a central location and then insert them into my projects as linked variables so that they update automatically when I change their values. For example, I define a variable named Product_Version that has its value set to 9. Then I insert this variable into all my projects as a linked variable. After 2 months the product version changes to 10, so I change the value of the variable to 10 in the location where it is stored and it is automatically updated in all the projects. Can this be done somehow? I'm new to RoboHelp and I can't find any answer. I've been searching for the solution for some time in the product help, on the Internet to no avail. I even contacted Adobe Support and they redirected me to this forum I used Help and Manual before and their way of dealing with user variables was pretty simple.

    Hi there
    Unfortunately RoboHelp doesn't offer up a way to allow this, At least, not directly.
    However, I do believe I found a way to make it happen, The variables are stored in a file named rhvariable.apj. So what you could do is to add this file as a Baggage File to each of your projects that will share the variables.
    Now you would create a Shared Location as well as a new Category in your Resource Manager. This will create a common location to store the apj file.
    Add the Baggage File to the location. Repeat the process for all projects that are sharing the variables.
    Now, when the variable gets changed in any of the participating projects, the shared location should be updated and you can accomplish the goal.
    However, note that even though you will have what you are wanting, it will still require opening each of the participating projects, synchronizing the APJ file and generating the output in order to update it all. No way I'm aware of to escape that.
    Cheers,,, Rick

  • Creating shared variables bound to I/O Aliases

    Hello,
    I'm running LabVIEW 2012. When I right-click on an .lvlib in the project explorer, there's a "Create Bound Variables" option. It's really convenient, as it automatically binds many variables to generic network-published shared variables simultaneously.
    However, it doesn't seem to support network-published I/O Aliases -- those libraries just don't show up in the dialog. I know that the I/O Aliases themselves work fine, because I was able to bind them manually, and then read them from my PC.
    Is there a way to automate the binding process for I/O Aliases?
    Thanks

    Hi Joey,
    It's mainly for maintainability.
    I/O Variables are grouped physically by chassis and module, not by purpose. My current project is a plant controller, using 3 CompactRIO chassis (linked by EtherCAT) and 20 C-series modules. The I/O ports for a logical part of the plant can be split across different modules (and even different chassis sometimes) -- thus physical grouping is suboptimal.
    Here is our simplified system architecture:
    We need variables hosted on the PC server for DSC logging, but also need variables hosted on the cRIO for robustness (e.g. in case connection with the PC server is lost).
    We have 2 primary reasons to create I/O Alias libraries, instead of binding directly to I/O Variables:
    It lets us group the variables more logically, which in turn lets us simplify our code for programmatic variable access. It's an abstraction layer between the hardware and the code. The logical groupings also help our developers better visualize the system.
    The client has not finalized their specifications, and the I/O port mappings might change. If we use I/O Aliases, we can just change the I/O Variable that the I/O Alias points to, and that's it. However, if we bind directly to I/O Variables, changing the hardware mapping will require us to change (i) the controller code, (ii) the I/O Variable that the PC variable points to, and (iii) (technically optional, but needed for readability) the I/O Variable name
    Anyway, since it is possible to (manually) create bindings to I/O Aliases, I'm surprised to hear it's expected behavior that we would not see the Aliases in Project items when we use the Create Bound Variables function

  • What is the best way to create shared variable for multiple PXI(Real-Time) to GUI PC?

    What is the best way to create shared variable for multiple Real time (PXI) to GUI PC? I have 16 Nos of PXI system in network and 1 nos of GUI PC. I want to send command to all the PXI system with using single variable from GUI PC(Like Start Data acquisition, Stop data Acquisition) and I also want data from each PXI system to GUI PC display purpose. Can anybody suggest me best performance system configuration. Where to create variable?(Host PC or at  individual PXI system).

    Dear Ravens,
    I want to control real-time application from host(Command from GUI PC to PXI).Host PC should have access to all 16 sets PXI's variable. During communication failure with PXI, Host will stop data display for particular station.
    Ravens Fan wrote:
    Either.  For the best performance, you need to determine what that means.  Is it more important for each PXI machine to have access to the shared variable, or for the host PC to have access to all 16 sets of variables?  If you have slowdown or issue with the network communication, what kinds of problems would it cause for each machine?
    You want to located the shared variable library on whatever machine is more critical.  That is probably each PXI machine, but only you know your application.
    Ravens Fan wrote:
    Either.  For the best performance, you need to determine what that means.  Is it more important for each PXI machine to have access to the shared variable, or for the host PC to have access to all 16 sets of variables?  If you have slowdown or issue with the network communication, what kinds of problems would it cause for each machine?
    You want to located the shared variable library on whatever machine is more critical.  That is probably each PXI machine, but only you know your application.

  • Binding shared variable in executable across network

    I can't seem to get a shared variable to bind from an executable on another computer back to a source variable on the main machine.
    I can get the remote variable to change with programmatic access.  Is it possible to have shared variables in an executable bind to a PSP URL on another computer?  This is labview 2011.
    I can see everything with NI Distributed System Manager, and the programmatic access changes the remote variable, so it's not a network issue.
    Thanks for any insights.  This just doesn't seem to work the way NI's online white papers say it shoud.

    What I don't understand is why after binding to a specific URL, the "Shared Variable Deployment" screen of the application builder makes the target "my computer". 
    I probably could get this to work if I changed the network address of "my computer" in the ini file created in Application Builder?
    This seem a strange way for this binding process to work.  If the absolute target (for shared variable bound to another variable and referencing "absolute") was retained when the VI goes through the application builder, it would make for sense.
    I can't get this to work any way with using bound variables.  The only way this works is using programmatic access to shared variables in the built app, and I don't consider this the same thing.
    My conclusion is that shared variable binding and appropriate absolute references to deployed variable libraries do not survive passing through the application builder with their absolute references intact.

Maybe you are looking for

  • Last hope..please help me

    Recently i brought my ipod mini of off my sister for $100 bucks.. and about a month after she gave it to me.. its decided not to work. now im a little peed off. I was listening to it..and the battery went dead. then... it would not turn on. i left it

  • Can't install compatible Symbian and .JAR files on...

    Hi. I have recently downloaded some free Symbian files over the internet, all compatible with Nokia 6120c. The problem is when I open up the Nokia Application Installer via Nokia PC Suite 3.84, I am able to browse for the downloaded files, but I am u

  • Flash 8 in iWeb?

    Is it possible to embed a Flash 8 video into iWeb pages instead of QuickTime? If so, where can I learn? Thanks!

  • Auto-play audio in Iweb

    Does Iweb support automatic audio play when site is opened capibilities?

  • Client Console Administration

    Dear Experts, I'm meeting unexpected system malfunctioning using the Client Console Administration on our Development Workstation (CRM Release 2007 / 5.0 SP 09) I am trying to connect to the CRM Server in order to generate the table script and the me