Will subsequent calls to an object running in a thread run in the thread?

Hi,
If I start a thread with an empty run method and then make a call to the object that I started in the thread, will the method call run in the other thread? For example:
class ThreadClass implements Runnable {
    public void someMethod() {
    public void run() {
class ThreadCaller {
    private ThreadClass threadClass;
    public ThreadCaller() {
        threadClass = new ThreadClass();
        Thread thread = new Thread(threadClass);
        thread.start();
    public blah() {
        threadClass.someMethod();
}Will the method call in blah() run in the same thread as ThreadCaller, or will it run in the thread that was started in ThreadCaller's constructor?
Thanks,
Dan

Djaunl wrote:
vanilla_lorax wrote:
Djaunl wrote:
Is there a way to keep the thread alive until the object that started the thread is terminated,Objects don't get terminated. What do you mean?I want the thread to stay alive indefinitely until I arbitrarily terminate it makes more sense. The thread will stay alive until its run method completes. The canonical approaches are
public void run() {
  while (!Thread.interrupted()) { // NOT isInterrupted()
    // do stuff
    // if you need to catch InterruptedException, do this:
    try {
    catch (InterruptedException exc) {
      Thread.currentThread().interrupt();
}And then from another thread, call theAboveThread.interrupt() when it's time to stop. Read the docs in interrupt(), interrupted(), the interrupt flag, etc.
OR
while (!done()) {
  // do stuff
}and then another thread calls setDone(true) or somesuch when it's time to stop. Note that all access to done--both get and set--must be synchronized, or done must be declared volatile. Also note that you may still have to handle interrupts, so you may have some repeated code with this approach--testing both done() and interrupted().
Let me give the end-goal of this.
Currently, I have a "main" thread which the user can input commands into, and another thread which occasionally runs in the background. When I want something to run in the background, I just create a new thread. However, I figured it'd be more efficient to have one thread running in the background to do something as opposed to spawning hundreds of new threads to do the same task over and over. If the task happens VERY frequently and what it does is VERY small and quick, then the overhead of thread creation may make this a valid approach. Otherwise, don't overcomplicate it. Since you're new to threads, first get it working where you spawn one thread for each background task. Then move on to thread pooling. Look into ThreadPoolExecutor and related classes.
http://java.sun.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html

Similar Messages

  • Calling a Flash object HTTPS (  only in IE, not loading the first time )

    Hi everyone !
    I'm trying to call a flash object from a bsp page, I've uploaded the flash into the mime repository (via the SE80). It works quiet well in Firefox, but with IE, i need to refresh the page, it won't load the first time i access the page.
    Does anyone has any idea ?? do i have to customize something within the SICF ?
    thx for the help
    merry Xmas
    Quentin

    Solved it, I created a page to call the flex from the MIME
    here it is :
    DATA: w_xstring TYPE xstring.
    DATA: w_mimetype TYPE string.
    * References
    DATA: w_url TYPE string.
    CONCATENATE 'sap/bc/bsp/sap/Z0008/' url  INTO w_url.
    CALL FUNCTION 'Z_FLEX_MIME'
      DESTINATION sy-sysid
      EXPORTING
        url        = w_url
      IMPORTING
        l_xstring  = w_xstring
        l_mimetype = w_mimetype.
    response->set_data( w_xstring ).
    navigation->response_complete( ).
    EventHandler Oninitialization :
    sap/bc/bsp/sap/Z0008/ is the url to my swf file in the SICF
    Module Function  Z_FLEX_MIME
    FUNCTION Z_FLEX_MIME.
    *"*"Interface locale :
    *"  IMPORTING
    *"     VALUE(URL) TYPE  STRING
    *"  EXPORTING
    *"     VALUE(L_XSTRING) TYPE  XSTRING
    *"     VALUE(L_MIMETYPE) TYPE  STRING
    * References
    DATA: lo_mr_api TYPE REF TO if_mr_api.
    * instantiate MIME API class
    CALL METHOD cl_mime_repository_api=>if_mr_api~get_api
      RECEIVING
        r_mr_api = lo_mr_api.
    * Get file from MIME repository
    CALL METHOD lo_mr_api->get
      EXPORTING
       i_url             = url
      IMPORTING
        e_content         = l_xstring
        e_mime_type       = l_mimetype
      EXCEPTIONS
        parameter_missing  = 1
        error_occured      = 2
        not_found          = 3
        permission_failure = 4
        OTHERS             = 5.
    ENDFUNCTION.
    If you have any questions please fell free to ask
    good day
    Quentin
    Edited by: Quentin Dubois on Feb 6, 2008 5:55 PM

  • Getting all the threads running in one JVM from another JVM ...

    I want to get all the threads running in one JVM from another JVM.
    Is it possible ?
    namanc

    I am going to write a java application that prints all the java application running at the background. And this application has a control over all the threads. means killing the threads, restart the thread etc
    namanc

  • Spring ..Can 1 interceptor intercept all calls to all objects within a clas

    My Building implementation contains Floor objects, which in turn contain Door objects. These floor objects are driven by the parent Building that contains them. If a Floor makes a call to a Door class this call can't be intercepted by the first buildingBean below. I had to create another one "floorBean" as listed below to catch these.
    Can the buildingBean be modified to catch all calls made by objects within them?
    <!-- Bean configuration -->
         <bean id="buildingBean" class="org.springframework.aop.framework.ProxyFactoryBean">
              <property name="proxyInterfaces">
                   <list>
                        <value>src.Building</value>
                   </list>
              </property>
              <property name="target">
                   <ref local="myBuilding"/>
              </property>
              <property name="interceptorNames">
                   <list>
                        <value>theTracingBeforeAdvisor</value>
                        <value>theTracingAfterAdvisor</value>
                   </list>
              </property>
         </bean>
         <!-- -->
         <!-- Bean Classes -->
         <!-- -->
         <!-- -->
              <bean id="floorBean" class="org.springframework.aop.framework.ProxyFactoryBean">
              <property name="proxyInterfaces">
                   <list>
                        <value>src.Floor</value>
                   </list>
              </property>
              <property name="target">
                   <ref local="myFloor1"/>
              </property>
              <property name="interceptorNames">
                   <list>
                        <value>theTracingBeforeAdvisor</value>
                        <value>theTracingAfterAdvisor</value>
                   </list>
              </property>
         </bean>
         

    Threads are part of code that allows you to run multiple operations "simultaneously". "Simultaneously", because threads are not run actually simultaneously in any one-CPU machine. Since you most propably have only one CPU in your system, you can only execute one CPU instruction at time. Basically this means that your CPU can handle only one java-operation at time. It does not matter if you put some code in thread and start it, it will still take up all CPU time as long as the thread runs.
    So you would need a way to let other threads run also, for that purpose thread contains a yield feature that allows you to give time for other threads to run.
    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Thread.html#yield()
    You need to use thread's yield() method in your thread code, in a place you want to give other threads time to run. Also bear in mind that if you yield your first thread run to allow second thread to run, you also need to add yield to the second thread also. If you don't, after yielding the first thread, the second thread will eat up all CPU time until it finishes, thus meaning the rest of your first thread will be run after second thread is done.
    One good place to execute yield() is usually at the end of a loop, for example 'for' or 'while' loop. This way you prevent for example while-deadlocks.
    Here is a java thread tutorial, worthy reading:
    http://java.sun.com/docs/books/tutorial/essential/threads/

  • Configure VI front panel for subsequent calls

    When you call a VI with an unwired input, the default value for the control is used. Most of the time, this makes good sense. But then how can you configure a VI to operate in a particular way, and subsequently call it to repeatedly perform some function given the prior configuration?
    For example, suppose I have a VI that works something like a virtual o-scope. I want to configure the instrument once (set up all the controls: time base, volt ranges, etc) and then periodically take readings. Is there any way to do this without having to wire the setup every time I take a reading?

    Use Action Engines or Functional Globals.  They make use of un-initialized shift registers.  Upon first call, the initilization must take place inside the vi.  The init values get wired to the shift registers on the right side.  Upon next call, the shift registers will retain the values that were set on the first call.
    See the Action Engine Nugget created by Ben.  Very useful and very practical.
    - tbob
    Inventor of the WORM Global

  • I have a production mobile Flex app that uses RemoteObject calls for all data access, and it's working well, except for a new remote call I just added that only fails when running with a release build.  The same call works fine when running on the device

    I have a production mobile Flex app that uses RemoteObject calls for all data access, and it's working well, except for a new remote call I just added that only fails when running with a release build. The same call works fine when running on the device (iPhone) using debug build. When running with a release build, the result handler is never called (nor is the fault handler called). Viewing the BlazeDS logs in debug mode, the call is received and send back with data. I've narrowed it down to what seems to be a data size issue.
    I have targeted one specific data call that returns in the String value a string length of 44kb, which fails in the release build (result or fault handler never called), but the result handler is called as expected in debug build. When I do not populate the String value (in server side Java code) on the object (just set it empty string), the result handler is then called, and the object is returned (release build).
    The custom object being returned in the call is a very a simple object, with getters/setters for simple types boolean, int, String, and one org.23c.dom.Document type. This same object type is used on other other RemoteObject calls (different data) and works fine (release and debug builds). I originally was returning as a Document, but, just to make sure this wasn't the problem, changed the value to be returned to a String, just to rule out XML/Dom issues in serialization.
    I don't understand 1) why the release build vs. debug build behavior is different for a RemoteObject call, 2) why the calls work in debug build when sending over a somewhat large (but, not unreasonable) amount of data in a String object, but not in release build.
    I have't tried to find out exactly where the failure point in size is, but, not sure that's even relevant, since 44kb isn't an unreasonable size to expect.
    By turning on the Debug mode in BlazeDS, I can see the object and it's attributes being serialized and everything looks good there. The calls are received and processed appropriately in BlazeDS for both debug and release build testing.
    Anyone have an idea on other things to try to debug/resolve this?
    Platform testing is BlazeDS 4, Flashbuilder 4.7, Websphere 8 server, iPhone (iOS 7.1.2). Tried using multiple Flex SDK's 4.12 to the latest 4.13, with no change in behavior.
    Thanks!

    After a week's worth of debugging, I found the issue.
    The Java type returned from the call was defined as ArrayList.  Changing it to List resolved the problem.
    I'm not sure why ArrayList isn't a valid return type, I've been looking at the Adobe docs, and still can't see why this isn't valid.  And, why it works in Debug mode and not in Release build is even stranger.  Maybe someone can shed some light on the logic here to me.

  • When importing a flash animation into captivate flash will not call external files

    Is there a way to import flash into captivate and it still be able to call external files (ie. sound, video xml)? When I import flash into captivate it will not call any external file.

    Hi all
    Wow, I was so hoping fellow Adobe Community Expert Paul Dewhurst would pop in on this thread.
    Why? Well, Paul sent me a way cool gizmo a while back that hacked the Info button. It used an external file for some of the information! So somehow Paul managed to sort what it took to insert a Flash object into Captivate and have that object extract data from an externally located file.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Business Graphics in ADS doesn't display on subsequent calls

    We have this bizarre problem with Business Graphics in ADS.
    We are embedding Business Graphics in an Adobe form and we find that the Business Graphics will not be displayed on second (subsequent) call(s) to the ADS, which can be simulated by clicking on the Refresh button in the web browser.
    The Business Graphics will only be displayed in the first call to the ADS.
    Has anyone encountered this?

    the problem is the URL that does not contain the jsessionId as during the second call. The browser has already a cookie and  so the encodeRedirectUrl-method does not add the parameter.                                                                               
    You can enforce this with the following call:                
    String url = "forceEncoding:" + source.getUrl();                             
    urlToBeUsed = ((IWebContextAdapter)WDWebContextAdapter.                      
    getWebContextAdapter()).encodeRedirectURL(url);

  • Is it possible to run a subVI in parallel with the caller VI?

    I have a front panel VI which calls numerous subVIs, one or two of which I would like to execute simultaneously with the calling VI. The front panel has time-dependant operations which are being prevented from running because it is waiting for the subVIs to finish, even though no data is required from them.
    Is it possible to call these subVIs such that they run silently in the background allowing the front panel to execute unhindered?
    I've looked at the Synchronisation features but is this what I need?

    shoneill wrote:
    > It's also very important to mention that the whole multi-threaded
    > execution CANNOT be reliably observed in highlighting mode in the
    > LabVIEW development environment. You need to let the VI run
    > full-speed to see this.
    >
    > Highlighting (to the best of my knowledge) forces single-threading, or
    > acts like it does.
    This is simply a convinience by LabVIEW since humans are inherently
    non-multi treaded. What you will see in parallel loops and which can
    still be distracting is that LabVIEW seems to randomly switch between
    different parts of your diagram. In fact this is also what is happening
    in normal execution but the execution switch is so fast (each individual
    operation typically taking microseconds it
    seems they execute in parallel.
    The nice part of LabVIEW since version 2.0 somewhere around 1988 already
    is, that it provides this seemless multithreading on every single
    platform even if the underlaying OS is not multithreading capable at all
    (Win3.1, MacOS).
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Building Applicatio​n for SCXI 1530, App will not call 1530 properly

    Hello,
    I'm working on building an application for a SCXI 1530. I have a scxi 1000 module with a scxi 1600-usb card. In slot 2 is the 1530 for accelerometers and in slot 4 is a card for lvdts (1540).
    I'm using labview developer suite 8.2.1 on a desktop to develop an application for a laptop. Right now I have created 2 very simple beta programs. One calls the 1540 for accelerometers and it works properly. Ready 1000 hz for 4 seconds. The other application with the accelerometer is the one I'm having trouble with.
    Here is what I know:
        Both applications were developed using DAQmx to setup the data acquisition event.
        Both applications work properly on the desktop, when run as a vi, and as a compiled application.
        The LVDT application runs properly on the laptop.
        The accelerometer application does not run on the laptop.
        The Measurement and Automation software shows that the 1530 (accelerometer card) is properly configured and that it is named identical to the desktop.
        The measurement and automation software will collect what looks to be reasonable acceleration data when configured to do so with a finite data collection of 1000 Hz.
    Any Help would be greatly appreciated.
    Paul

    Kent,
    Here are some answers to your questions and a followup on my current status.
    First let me describe my program a bit. Basically within a while loop there is a case loop controlled by a 'run' button. When that 'run' button is pushed the program is to collect data. On the desktop it works perfectly collecting real data. On the laptop the first time the run button is pushed after starting the application nothing happens. None of the graphs or indicators change their apperance or value. If I push the run button again, the graphs change to an x-axis range of -1 to 1, and maximum value indicators range from -10 to -45 (that seems to be pretty random). One more thing the program is set to record 4 seconds of data at 4kHz. All this time there are no errors and the program continues to run.
    One of the first things I checked was to validate the name being the same, and those are identical. The next thing I checked was to make sure that the 1530 was working properly using the NIDAQmx test panels in measurement and automation. Everything there seemd to work fine and appeard to be recording reasonable data.
    Late last night I decided that I'd reinstall drivers on the laptop. Thinking 'what could it hurt?' After reinstalling the drivers the application works on the laptop. So I suppose the lesson I learned was even though the MEasurement and Automation test panels work when in doubt re-install drivers.
    As of now everything appears to be working properly.

  • Calling a Script Object after remove instance index[0]

         I have created a LiveCycle document that has a repeatable subform as url linked below. The form will not let me call a Script Object after removing an instance at index[0]. Regardless of the number of instances remaining. I use a script object to show and hide buttons. Adding an instance is not a problem. What to do?
    Script on Delete Subform Button (Error):
    xfa.form.recalculate(1);
    this.resolveNode('fifteenSubform._CorrectiveActionWrapper').removeInstance(this.parent.ind ex);
    if (xfa.host.version < 8) {
    //deleteing a [0] index seems to create a problem for executing the function in this Script Object
    SOremove.fxremove();
    https://files.acrobat.com/a/preview/03389d79-9020-45d9-ba4f-fb4cbdc21f77

    Hi,
    What seems to happen when you remove a form object that has code that is currently executing is that it can't find the next line.  You might want to put all your code in the script object.
    so in the click event you have;
    SOremove.fxremove(this);
    Then your script object will start
    function fxremove(button) {
        button.resolveNode('fifteenSubform._CorrectiveActionWrapper').removeInstance(button.parent.index);
        if (xfa.host.version < 8) {
            xfa.form.recalculate(1);
        console.println("The SOremove.fxremove fired");
    Regards
    Bruce

  • Report that will be called from CIC0

    can anyone elaborate this statement "report that will be called from CIC0"
    whats the process?

    hi arun
       u can  easily  access them  in  SWO1 tcode
    IS_BUS1006 Business Partner for Drag&Relate Insurance
    ISA_FLMP   Vendor's mail partner for material ordered via rel
    ISA_T024D  MRP controller group (ISA)
    ISPPDOCUM  CA Document for IS-IS/CD
    ISSR2      Customizing
    ISTBILLDOC Telco Billing Document
    ISTFILEHIS Transfer of telephone number disconnection file
    ISU_EQUI   Equipment (+ IS-U Functions)
    ISU_IAC    Internet object
    ISU_PRICE  IS-U: Price
    ISUACCOUNT IS-U: contract account
    ISUACCTCLS IS-U: Account Class
    ISUADDRESS IS-U: Address
    ISUBUSVIEW IS-U: information view
    ISUCONTACT Customer Contact (IS-U)
    ISUCONTRCT Utility contract
    ISUCRM1O   Activity in CRM
    ISUCRMCNCT ISU-CRM Connector
    ISUCRMCNTR ISU-CRM Contract (CRM Order Item)
    ISUDERSUP  IS-U deregulation help
    ISUDEVINFO Device info record
    ISUFFEE    IS-U: franchise contract
    ISUFINDER  IS-U search function (data finder)
    ISUGBCIF   GIS Business Connector Interface
    ISUGRID    Supply Grid
    ISUIDEPROC IS-U: IDE process
    ISUIDESWD  IS-U-IDE Switch Document
    ISUIDETRAN IS-U: IDE transaction
    ISUIDOCLOG Application log IS-U
    ISULOT     IS-U: sample lot
    ISULOYACC  Loyalty account
    ISUNBSERVC Point of delivery service (not billed)
    ISUPARTNER IS-U: business partner
    ISUPOD     Point of Delivery
    ISUPRDOC   IS-U: Parked Document
    ISUPRODLOG Product log IS-U
    ISUPRODUCT Utility product
    ISUPROFILE Profile in Energy Data Management (EDM)
    ISUPROP    Owner allocation
    ISUREDEMP  Redemption Document for Loyalty Account
    ISUSDCONF  SD configuration
    ISUSDORDER IS-U: Sales Order
    ISUSDORPOS IS-U: Sales Document Item
    ISUSDQUOTA IS-U: Customer Quotation
    ISUSECTOR  IS-U: division
    ISUSERPROV ISU Service Provider
    ISUSERVICE Utility service
    ISUSETTL   ISU-EDM: Settlement
    ISUSETTLUN ISU Settlement Unit
    ISUSLDCMNT Document/sub-ledger document
    ISUSMNOTIF IS-U: Service notification
    ISUSMORDER IS-U: Service Order
    ISUSRVPROD IS-U: Service Product
    ISUSUPSCEN Supply Scenario
    ISUSWITCHD IS-U-IDE Switch Document
    ISUSWTELOG Error Log for Switch Document
    ISUTASK    IS-U: Data Exchange Task
    ISUWIMUSER Work item with user interaction
    kr
    raj

  • Thread run() can't return an object?

    I am using threads with Runtime.exec() to run system commands (like ps command on Unix) and I need to have the method return what the executed commands return e.g. the response from the ps command; however, the run() method in the Thread interface is void.
    Is there any way around this?

    hello David,
    as far as i understand with thread, it doesn't return anything, if you like you could create a static class or method (setter and getter) that would contain the values you need.. and once in a while check it..
    say, in your thread it will get a response right? after the Runtime.exec(), you call the class set method, then in the calling class of the thread, put a loop.. as i understand you have to wait for the runtime.exec reply.. so, try to put a loop that would call the class get method.
    i hope it helps,
    Ronron

  • My track pad highlights applications and files and then opens them without my doing anything. I run MacKeeper and having run the scan several times only get cleaning issues (5 -). Any ideas as MacKeeper Kromtech have not responded to my calls nor email.

    Folks
    I run an iMac. Today for some reason when I run the cursor across the screen applications and files are highlighted and then opened without me doing anything (no clicking etc) In fact print at times opens. As far as I can tell I have not changed any settings except to open firewall.
    I run MacKeeper and when I run a scan only a few cleaning items open. Safe and fast are as they should be. I run fix. If I again run the scan I get a few more but different claeing items to fix.
    I have rung MacKeeper several times without getting through. The occasion I did get through the bloke said he could not help and passed me to a higher authority. Needless to say the line dropped out after 30 minutes waiting.
    As it is the weekend and I do not live near an Apple store I am quite keen to get the problem identified and fixed so I can continue working.
    Your assistance please.

    Remove the "MacKeeper" scam product as follows. First, back up all data.
    "MacKeeper" has only one useful feature: it deletes itself.
    Note: These instructions apply to the version of the product that I downloaded and tested in early 2012. I can't be sure that they apply to other versions.
    IMPORTANT: "MacKeeper" has what the developer calls an “encryption” feature. In my tests, I didn't try to verify what this feature really does. If you used it to “encrypt” any of your files, “decrypt” them before you uninstall, or (preferably) restore the files from backups made before they were “encrypted.” As the developer is not trustworthy, you should assume that the "decrypted" files are corrupt unless proven otherwise.
    In the Finder, select
    Go ▹ Applications
    from the menu bar, or press the key combination shift-command-A. The "MacKeeper" application is in the folder that opens. Quit it if it's running, then drag it to the Trash. You'll be prompted for your login password. Click the Uninstall MacKeeper button in the dialog that appears. All the functional components of the software will be deleted. Reboot.
    ☞ Quit MacKeeper before dragging it to the Trash.
    ☞ Don't empty the Trash. Let MacKeeper delete itself.
    ☞ Don't try to drag the MacKeeper Dock icon to the Trash.

  • Flex Builder 4 (next version) will be called Flash Builder

    Adobe has just announced that the next version of Flex Builder will be called Flash Builder .. the framework will still be called Flex
    I think although the change is confusing, in the long run it adds clarity ... here's why ...
    1. Flash Builder (formerly Flex Builder) is an IDE to write .SWF (Flash Player) files .... no matter what application framework you use, it could be pure AS3 code (i.e your own framework) , Flex framework or anything else .. there are many other framework options (although Flex is the most mature) ... Flash Builder can be used to build in any of those frameworks.
    2. Flex is a framework of classes that solve several everyday application development problems when building apps that can run in the Flash Player ... you can use any tool to write your own classes that use flex framework classes (a flex application) ... Flash Builder (previously Flex Builder) or FDT or a text editor like TextMate.
    Mrinal

    Still don't like the name change...but after chatting for you on Twitter...I think I can use to it -;)
    Greetings,
    Blag.

Maybe you are looking for

  • ACS 5.3 Accounting

    Hello all, I need to help with accounting in ACS 5.3. When I setup accounting on WLC 440x / 5508 ACS takes them as an authentication request and fail. Here are some logs what I see in acsview: Dec 9,11 6:05:11.783 PM Radius authentication failed for

  • How to clen up the R12  Instance in Windows 2003 server.

    Hi, We have two R12 instances running on the same server (vision and Development). and want to scrap Vision instance. Please explain me how to uninstall the R12 Application instance. The Note 107523.1: How to Clean Up a Failed Install of Oracle Appli

  • Can i install samsung 850 pro 1 tb solid state drive in my "macbook pro 2012 mid".

    Hi, anyone know. can i install samsung 850 pro 1 tb solid state drive in my "macbook pro 2012 mid". any compatibility issues?

  • Using External Hard Drives...

    How many external hard drives can be connected to FCP? I am NOT asking how many can be connected at one time. In the scratch disc section, I have my external set to capture video/audio and to save project files and self contained movie files and othe

  • Domain Name v IP Address

    Hi, I am running a windows 2003 network using a Microsoft exchange server. I have added imacs and other Macs to the domain with no problems they can see the exchange server and all accounts have their email addresses, however when I try adding an acc