retrieving information up the stack

Discussion in 'Java' started by ben@kafkaville.com, Jun 5, 2007.

  1. Guest

    I have a need to traverse up the stack, access a particular calling
    object and retrieve an instance variable via a getter. Was wondering
    if anyone knows how to do this. I can identify the caller through the
    StackTraceElement but don't know how I can retrieve the object to
    reflect on the getter. IDE's do this some how when debugging.
    , Jun 5, 2007
    #1
    1. Advertising

  2. On Jun 5, 9:12 am, wrote:
    > I have a need to traverse up the stack, access a particular calling
    > object and retrieve an instance variable via a getter. Was wondering
    > if anyone knows how to do this. I can identify the caller through the
    > StackTraceElement but don't know how I can retrieve the object to
    > reflect on the getter. IDE's do this some how when debugging.


    When debugging, IDEs use the JVM's external debugging hooks, which are
    not[1] available to applications running inside the JVM. Furthermore,
    that kind of stack grovelling introduces some truly hairy and subtle
    dependencies between the callee and the caller; I seriously doubt that
    it's the best way to accomplish, well, anything.

    What are you aiming to do with the information you get from this
    getter?

    [1] readily
    Owen Jacobson, Jun 5, 2007
    #2
    1. Advertising

  3. Guest

    On Jun 5, 10:27 am, Owen Jacobson <> wrote:
    > On Jun 5, 9:12 am, wrote:
    >
    > > I have a need to traverse up the stack, access a particular calling
    > > object and retrieve an instance variable via a getter. Was wondering
    > > if anyone knows how to do this. I can identify the caller through the
    > > StackTraceElement but don't know how I can retrieve the object to
    > > reflect on the getter. IDE's do this some how when debugging.

    >
    > When debugging, IDEs use the JVM's external debugging hooks, which are
    > not[1] available to applications running inside the JVM. Furthermore,
    > that kind of stack grovelling introduces some truly hairy and subtle
    > dependencies between the callee and the caller; I seriously doubt that
    > it's the best way to accomplish, well, anything.
    >
    > What are you aiming to do with the information you get from this
    > getter?
    >
    > [1] readily


    I'm writing a custom logger that writes to the database. This logger
    groups a set of logs with a "processObjectId" which is associated with
    a batch run. For example, the dailybulletinprocess as 6 main classes
    that get invoked. These classes each invoke additional classes that
    are running in all types of unrelated contexts. I want to be able to
    retrieve my logs only in the context of the "dailybulletinprocess". I
    cannot specify this in the Logging statement because the contexts
    differ. I also don't want to pass this info to each class as that
    would begin to smell.
    I was thinking if I could set a variable in a top level constructor
    and access it up the stack it would solve my problem.
    , Jun 5, 2007
    #3
  4. Guest

    On Jun 5, 10:40 am, wrote:
    > On Jun 5, 10:27 am, Owen Jacobson <> wrote:
    >
    >
    >
    > > On Jun 5, 9:12 am, wrote:

    >
    > > > I have a need to traverse up the stack, access a particular calling
    > > > object and retrieve an instance variable via a getter. Was wondering
    > > > if anyone knows how to do this. I can identify the caller through the
    > > > StackTraceElement but don't know how I can retrieve the object to
    > > > reflect on the getter. IDE's do this some how when debugging.

    >
    > > When debugging, IDEs use the JVM's external debugging hooks, which are
    > > not[1] available to applications running inside the JVM. Furthermore,
    > > that kind of stack grovelling introduces some truly hairy and subtle
    > > dependencies between the callee and the caller; I seriously doubt that
    > > it's the best way to accomplish, well, anything.

    >
    > > What are you aiming to do with the information you get from this
    > > getter?

    >
    > > [1] readily

    >
    > I'm writing a custom logger that writes to the database. This logger
    > groups a set of logs with a "processObjectId" which is associated with
    > a batch run. For example, the dailybulletinprocess as 6 main classes
    > that get invoked. These classes each invoke additional classes that
    > are running in all types of unrelated contexts. I want to be able to
    > retrieve my logs only in the context of the "dailybulletinprocess". I
    > cannot specify this in the Logging statement because the contexts
    > differ. I also don't want to pass this info to each class as that
    > would begin to smell.
    > I was thinking if I could set a variable in a top level constructor
    > and access it up the stack it would solve my problem.


    Best solution I've come up with so far would be to log all batch stuff
    to a file and when done, the top level class would parse it and suck
    it into the database logging tables.
    , Jun 5, 2007
    #4
  5. wrote:
    ....
    > I'm writing a custom logger that writes to the database. This logger
    > groups a set of logs with a "processObjectId" which is associated with
    > a batch run. For example, the dailybulletinprocess as 6 main classes
    > that get invoked. These classes each invoke additional classes that
    > are running in all types of unrelated contexts. I want to be able to
    > retrieve my logs only in the context of the "dailybulletinprocess". I
    > cannot specify this in the Logging statement because the contexts
    > differ. I also don't want to pass this info to each class as that
    > would begin to smell.
    > I was thinking if I could set a variable in a top level constructor
    > and access it up the stack it would solve my problem.
    >


    Why not set a thread local variable in the top level constructor? See
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/ThreadLocal.html#ThreadLocal().

    Patricia
    Patricia Shanahan, Jun 5, 2007
    #5
  6. Guest

    On Jun 5, 12:38 pm, Patricia Shanahan <> wrote:
    > wrote:
    >
    > ...
    >
    > > I'm writing a custom logger that writes to the database. This logger
    > > groups a set of logs with a "processObjectId" which is associated with
    > > a batch run. For example, the dailybulletinprocess as 6 main classes
    > > that get invoked. These classes each invoke additional classes that
    > > are running in all types of unrelated contexts. I want to be able to
    > > retrieve my logs only in the context of the "dailybulletinprocess". I
    > > cannot specify this in the Logging statement because the contexts
    > > differ. I also don't want to pass this info to each class as that
    > > would begin to smell.
    > > I was thinking if I could set a variable in a top level constructor
    > > and access it up the stack it would solve my problem.

    >
    > Why not set a thread local variable in the top level constructor? Seehttp://java.sun.com/j2se/1.5.0/docs/api/java/lang/ThreadLocal.html#Th...().
    >
    > Patricia

    Yes was thinking along those lines to some extent. My explanation was
    somewhat simplified of the use case. These processes (within the batch
    context) are distributed to random machines, each runs an Eclipse rich
    client, which spins off a new thread for the particular task it's
    doing. My thought, after ruminating over lunch on it, is to record the
    machine name (gotten from the stack), and the thread number(s) in a
    table and associate them with the process objectid. I will pass the
    process object id to the instantiated upper level class and store it
    in the database and a ThreadLocal variable.
    , Jun 5, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Surinder Singh
    Replies:
    1
    Views:
    1,175
    Richard Bos
    Dec 20, 2007
  2. Casey Hawthorne
    Replies:
    3
    Views:
    1,065
    Flash Gordon
    Nov 1, 2009
  3. Debajit Adhikary
    Replies:
    36
    Views:
    2,247
    Andre Kaufmann
    Feb 10, 2011
  4. Sam Roberts
    Replies:
    1
    Views:
    212
    Yukihiro Matsumoto
    Feb 11, 2005
  5. Kenneth McDonald

    Why stack overflow with such a small stack?

    Kenneth McDonald, Aug 30, 2007, in forum: Ruby
    Replies:
    7
    Views:
    247
    Kenneth McDonald
    Sep 1, 2007
Loading...

Share This Page