What's an easy way to start an agent in current JVM after it is running?

I want to be able to start a Java agent in the current JVM. I cannot control how the JVM is started, therefore I cannot specify -javaagent on the java command.
I know the attach API lets me attach to a JVM if I have its PID. But unless I have missed something there is no platform-independent way of getting the current PID to pass to VirtualMachine.attach.
I have run an experiment that seems to work in which my code:
1. Uses File.createTempFile to create a unique temp file.
2. Sets a system property to the temp file's path.
3. Uses VirtualMachine.list to get VirtualMachineDescriptors for all known VMs.
4. For each VMD:
4a. Attaches to the VM using theVirtualMachineDescriptor.id().
4b. Retrieves the system properties from the VM.
4c. Searches the Properties for the system property name and, if found, checks its value.
4d. If they match, the VirtualMachine in the loop is the currently-running VM one and do what I want.
4e. If they do not match, detach from that VM and check the next VM in the list.
This is terribly cumbersome, plus it requires that tools.jar be available.
Is there no simpler way to establish an agent in the current VM? Or to attach to the current VM?
(I also tried passing an empty string and "-1" as the PID to VirtualMachine.attach with no luck. Not that I expected those to work, given that the JavaDoc said nothing about these special values.)
Thanks.
- Tim
Edited slightly for clarity by: tjquinn on Jan 23, 2008 4:26 PM

Thanks a lot for the pointers, Alan.
The real underlying difficulty I didn't mention earlier is that Java Web Start is launching the applications of interest here. The JNLP spec currently provides no way of indicating an agent in the JNLP document, the -javaagent command line option is not one of the ones that Java Web Start chooses to handle (for the obvious security reasons I presume), and JNLP provides no mechanism for defining environment variables. So perhaps this is a lost cause until the JNLP spec and/or the Java Web Start implementation evolve.
(There is a bug from years ago filed against Java Web Start asking for the equivalent of the -javaagent feature.)
My questions in this thread reflect my (unsuccessful) attempts at side-stepping those Java Web Start restrictions.
It does seem to me that the management enhancements over the past several Java SE versions have done a nice job of allowing different JVMs to manage and monitor each other. The special case of a JVM managing or monitoring itself is not so easy. In my particular case I don't really need the ability to attach to a different JVM. If I could just get the VirtualMachine instance for the current JVM (without needing tools.jar) I'd be done and on my way.
Is that worth an RFE against management/monitoring do you think?
- Tim

Similar Messages

  • What is the easier way to turn voice controller off?

    what is the easier way to turn voice controller off?

    you can turn of the voice dial but as far as i know you can not turn off the voice controller
    if you want to turn of the voice dial just go to setting then to general after that to passcode and turn off the voice dial option

  • What is an easy way to scan old photos? I have a brother DCO 7-4- printer scanner

    what is an easy way to scan old photos?  I have a brother DCP 7040 printer

    Try Image Capture.
    Eight amazing Image Capture tricks | Digital Photo | Macworld

  • What is an easy way to get to my app store on my computer?  I can never just go to it and usually end up there by pure luck.

    what is an easy way to get to my "app" store on my computer?  I usually just stumble upon it my chance.

    If you mean the App Store for your iOS devices, that is in iTunes. If you are running iTunes 12, then you would select the App icon in the toolbar, then select Store:
    Cheers,
    GB

  • What's an easy way to determine what the user typed is a date object?

    What's an easy way to determine what the user typed is a date
    object?
    Thanks!

    Thanks for trying. Sorry for not being clear. but I figured
    it out.
    the user can type in a date, or a name to search. The format
    they type in date has to be in mm/dd/yyyy.
    I was able to use:
    if (new Date(textEntered).toString()=="Invalid Date") {
    // not a date entered
    else {
    // a date is entered
    To do what I need to do.
    Thanks.

  • What is the easier way to edit a captured slide?

    I have created a demonstration animation and there are several slides that need a little graphics editing.
    So far, I have not found a way to automate the process of editing slides.
    The only method I can determine is by selecting "Copy Background", then opening a graphics editor, pasting to a new window, edit accordingly, save the edited graphic background, import into the slide.
    Isn't there anyway to edit inline?.. meaning, the background is automatically sent to your choosen graphics editor, you edit the graphic, click save/exit, and the graphics background is automatically updated. That is how Captivate 4's competitors do it.

    Hi Shawn
    It really depends on what exactly you need to do. For example, if all you want is an easy way to blot out some words, use a Highlight Box object at zero percent transparency. Then merge it into the background. Or maybe you need an image added in. Add the image separately and merge it.
    Last week we needed to render an option button as unselected. In that case I just right-clicked and opened in Microsoft Paint. Duplicated another and overlaid the errant one. Closed and saved. Total update time from start to finish was less than two minutes.
    Cheers... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • What is the best way to start "fresh" with iPhoto '08?

    I am running iPhoto '08 on a mid-2007 iMac. When I set up the machine, I moved all the photos from my PC to the Mac retaining the existing directory structure that I had on the PC. I then imported all the pictures into iPhoto with no problems.
    Unfortunately, the other person who uses the Mac needs to be able to use the directory structure as it existed on the PC (that structure involves several subfolders with specific names etc.), and it appears that iPhoto is not designed to work that way. I know the photos can still be manipulated in the folders I imported, but then I run the risk of at best, being out of synch with iPhoto and at worst, corrupting iPhoto completely.
    That said, what I would like to do is delete or remove the current iPhoto library (or whatever iPhoto accesses; not the whole application unless necessary) and then selectively import photos to iPhoto. That way, the other user can access the photos in the familiar folder structure and manipulate them at will without disturbing the iPhoto db and, once photos are edited etc. and ready for primetime, they can be imported to iPhoto to gain the advantages of displaying using Front Row etc.
    My question is what is the best way to achieve what I am looking for? Just backup then delete the iPhoto pkg file in the HD/Library/Receipts folder? Uninstall the entire application and start over?
    All assistance greatly appreciated.

    ETRA
    Welcome to the Apple Discussions.
    You don't need to re-install iPhoto, just change the library - and you may not even need to do that.
    1. You can easily recreate your Directory structure in iPhoto. Simply start at the bottom of your structure and drag a folder of images to the Source (or left hand) pane of the iPhoto Window. iPhoto will create an Album of the same name. The create your enclosing folders (File -> New Folder) and drag the albums to it. This way you can quickly recreate what you have/
    2. The other user of the files can access them directly via the iPhoto Window or a Media Browser such as THIS. The advantage of this system is that your directory structure is available to them ina convenient and recognisable way. They can then drag the pics from the iPhoto Window / Media Browser to the app they as the need. (A whole lot faster than fumbling around in Folder after Folder etc, plus the advantage of keyword searching.)
    3. Is this necessary for working with an editor? You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. Btw this is the only way that edits made in iPhoto will be visible in iPhoto.
    4. Finally, if you do wish to go as you described: Simply trash the iPhoto Library from the Pictures Folder. Start iPhoto and it will create an new empty library. If you wish to recover the files from the Library first, then Right Click on the iPhoto Library and go 'Show Package Contents'. Your files are in the Originals Folder.
    Regards
    TD

  • What is the best way to start SAPGUI in a specific transaction

    Hello,
    What I'm trying to do is to run a Java program that will start SAPGUI (in windows format, not HTML) and present the user with a specific transaction with some data already inserted.
    I already managed to start the SAPGUI and I know how to fill in data using the SapJCo but my question is: what is the best way to navigate to a specific transaction? I can activate an RFC of BAPI_CALL_TRANSACTION but it seems like a big overhead. so, can any of you tell me what is the best way activate a specific transaction in SAPGUI using JCo?
    Thanks,
    Uri Lifshitz.

    Uri
      JCO are mostly used to executed a RFM on the Destination.
      I don't think we could call a Transaction using JCO.
    Thanks
    Jack
    <b>Allot points if my post helps !!!</b>

  • What is the "easy" way to get to 3.1.2?

    I've "loved" the Oracle database for many years, and is thrilled with Apex. I no longer work as a DBA, but tries to keep my technical stuff close.
    I have an Apex 2.1 installation on an 10g database on Ubuntu 8.10 server. I did the lazy install then, and installed via aptitude (more or less automated install).
    I would like to install 3.1.2, but must admit I almost lost courage when I read the requirements.
    My Oracle install right now can be discarded, so I wanted to ask: what is the easiest way for me to get 3.1.2 installed on Ubuntu?
    Install the latest version of 11g? Run a magic script, that automates all that Oracle exhaustively describes?
    Thanks in advance
    Yours
    /Kim
    End note/rant: given that oracle can describe everything in such details, why oh why, not just build an installer around it?! the chances of errors are multitudes greater with all these nitty gritty commands. My SQL Server DBAs routinely updates, installs and patches SQL Server without much of a hassle. Oracle DBAs gets ticks thinking of the testing needed...

    Just to be clear, you're probably running Oracle Express Edition, or "XE" based on the fact that you installed it via aptitude and it has APEX 2.1 pre-installed. It may say 10g when you login, but please refer to it as XE in the forums so people know what db they're dealing with.
    There is no "easy" way to magically install 3.1.2. You have to follow the install guide to the letter now matter what path you take. Even if you install 11.1, it only has APEX 3.0 pre-installed. Even though I really prefer 11 to 10, I think your best off sticking with XE, especially since there are no licensing issues. For what it's worth, I've suggested that APEX needs a GUI installer (such as Oracle Universal Installer) for several years now since the install / upgrade process can be a bit daunting. Until the community demands it, I don't think it's going to happen, so please, speak up if you think the install process is too hard.
    Tyler

  • What are different possible ways to start a process?

    Wondering what are different possible ways in which I can trigger a process in Aqualogic BPM.
    I have worked on WLI & there with the use of channels & event generators I could able to trigger my process for almost any event, be it file system update, Http Request or Database update.
    Can I trigger a process in Aqualogic BPM on arrival of a new file in file system (directory)?
    Any pointer towards documentation would also help.

    Hi,
    There are a lot of ways to trigger the process. You can execute any code based on a timming event, or external events such as JMS queues. Polling directories/webservers etc. is really easy.
    I'd suggest you take a look at the Studio documentation and read about Global Automatic activities.
    Hope this helps!
    Fernando

  • What's a easy way to rename my network.

    I am using Airport Express and its great but i don't like my network name, others around can see my name i didn't think of that since i just got it today.
    Anyone know of a easy way to rename my network or wifi.
    Thanks for any help in advance.

    thanks Alan but there is a error when i do it that way.
    i Have to use the setup assistant then selecting edit existing, someone from a Australian forum called Whirlpool helped me out funny thats the one i didn't try even though i just set up my AirPort today and i saw that option thanks for you help!

  • What is an easy way to log and share lists (grocery, mileage) with my wife?

    My wife and I have all the Apple devices and would like an easy way to share lists; specifically, a grocery list and a mileage list.  The latter is for whenever each of us drives our personal vehicle for business use.
    If it was just me, I can create a Numbers spreadsheet and save it to the Cloud.  Then, it's accessible from all my Apple devices.  But she and I need to be able to hit the same documents.
    I've seen some apps in the iOS AppStore, but don't need all those bells and whistles.  Can't I just grant her access to my Numbers document in my cloud or something?
    Thanks for any advice.

    Hi rcook,
    If you are both on the same iCloud account, then by far the easiest way to share (and update) notes is to use the Notes app. I use it for all of my "to do" and "grocery lists" among other things. I can updae it on my Mac, and with I go to the store - it is there waiting for me on my iPhone! No syncing, required, If is check somethng off, or delete it, then if my husband is looking at/using the same list, he knows that itm is taken care of.
    Not sure if this fits your needs, but it works great for us!
    Cheers,
    GB

  • What is the best way to keep 7 days most current data in tabledata

    Hi,
    Can anybody help me to keep most recent 7 days data in a table? any data older than 7 days should be removed which cen be done once a day.
    What is the best way to do this? partition, re_create table or anything else?
    Thanks
    George

    Have you considered partitioning the table? You could then drop the oldest partition every day, which would be marginally quicker & easier than deleting the 10,000 rows. 100,000 rows is a pretty small table to partition, but it may be worth considering.
    I wouldn't expect there to be a significant difference on query performance no matter how you set this up. You won't reset the high water mark, but that is only important when you are doing a full table scan and Oracle will reuse the space for the current day's data, so it's not like the high water mark will be constantly increasing.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • What is the best way to clean up your mac and make it faster and run to an optimum level?

    Hi Everyone, Hope all is well
    Iv been running my mac pro for a long time now, its a Mac pro, 2x 2.26 GHz Quad Core Intel Xeon. 12 GB 1066 MHz DDR3 Ram
    Over time now it has become slower, at the moment its still running fine but im sure over time it has probabally collected unwanted data etc. i just dont want it to become a problem as its only going to be used more and more... i now notice that some of the regular programs which i open do take a little while longer to open and i sometimes see that little round Mac loading the sign (the round multicolor wheel).., is there a way to clean the mac up? so that it can run more smoothly and just a better over all feel.,,, the machine is still running beautifully but its time i give it more care and revive it a little more..
    What are the best ways to do this, i dont trust any of these non apple based products which claim they can clean ur Mac etc.
    Any solutaion and advice that u guys can give would be great and i would be very thankful
    Thanks in advance

    For immediate speed improvements, upgrade to a Solid State Drive and upgrade your conventional hard drives to new ones, because the newer ones are faster at reading and writing than the ones from 5 years ago.
    By Re-installing your OS onto a solid state drive, the system will boot much faster, and your programs will launch much faster.
    I use a small SSD (only 60GB) which contains only OS X and all my apps.  All of my personal files are on the large mechanical hard drive.  If you still use the drive that shipped with the Mac, then it might be a good idea to replace it.
    Depending on what kind of work you do, then additional RAM will help.  Swapping CPUs should only be done if you are really in need of the improvements they would bring. 
    You appear to have the 2009 dual-CPU Mac Pro, which is the most challenging model to swap CPUs into.

  • What is the best way to update leopard to the current os x version?

    I am still running Leopard and I was just wondering what the fastest / cheapest way of updating my system to the current software is?

    We know nothing about your computer. Maybe it cannot run anything newer; maybe it can. Get more information about your computer. Go to the Apple in the upper left corner of any window, then "About This Mac", then "More Info..."  Copy and paste the information here, but omit the serial number and Hardware UUID (if present).
    Compare with:
    OS X Lion (10.7) Technical Specifications - http://support.apple.com/kb/SP629
    Installing Lion: Our complete guide - http://www.macworld.com/article/161064/2011/07/installing_lion_complete_guide.ht ml
    How to install Lion over Leopard - http://www.macworld.com/article/161087/2011/07/install_lion_over_leopard.html
    OS X Lion: Installation Guide, Boot Discs and Q&A - http://www.macstories.net/mac/os-x-lion-installation-guide-boot-discs-and-qa/
    Lion application compatibility - http://www.everymac.com/mac-answers/os-x-lion-faq/os-x-lion-compatible-incompati ble-applications-quicken-office-eudora.html
    Lion application compatibility (2) - http://www.everymac.com/mac-answers/os-x-lion-faq/how-to-check-powerpc-applicati ons-not-compatible-with-os-x-lion.html
    Lion and Mountain Lion application compatibility - http://roaringapps.com/apps:table

Maybe you are looking for