• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Process ID?

 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I get the process id, thanks.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean like this?

Process p = Runtime.getRuntime().exec("command.com /c start java abc");
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, that runs a command outside of java? So I could say something like "getpid" (I am running on unix).
Why isn't there a pid from within java. I am a process within a java machine, or something like that. I must have an identifier of some sort? How does java keep track of the different processes?
Thanks.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The variable name IS an id. It holds a reference to the object that is the process. Why would you want to bypass the simplicity of java by junking it up with native process calls??
And yes, you could use the above statement to start a .bat file or something (I am not a unix person, so I don't know what os commands you would want to start).
In windows you can directly execute an application or use the above to execute a command.
Process p2 = Runtime.getRuntime().exec("notepad.exe");
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no desire to run non-java stuff from within java. I thought that is what you were telling me "exec" did.
What I need is a unique identifier for a thread running in application server #1 vs a thread running in application server #2. Assuming that both application servers are running on the same machine.
I already figured out how to get time in milliseconds & host name, and now need the last component of the unique id. I was thinking that the process id of the application server would do that for me.
Thanks.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why??? What is the final intended result. I have got to think that you are going about this the hard way.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to generate a unique identifier, for a thread (servlet). Unique if I have multiple threads (servlets) on one application server. Can have more than one application server per host. And can have multiple hosts.
I already have the timestamp and hostname, now I need a way of knowing if a thread on application server #1 is different than thread on application server #2, on the same host.
Thanks.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is a thread you can do a getName() on it. And you can do a getThreadGroup(). And you can find out which JVM it is running on using getContextClassLoader().

 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The documentation that I have read states that different threads can have the same name using getName(). So that will not work for me. getContextClassLoader() sounds promising - I will look into that. Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic