Results 1 to 9 of 9
  1. #1
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default Thread/method call analysis

    Is there a tool for analyzing which threads call which methods, and non-local variable access in methods called in more than one thread, to highlight potential thread safety problems? It would be especially awesome if it could analyze Android projects.
    Get in the habit of using standard Java naming conventions!

  2. #2
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    131
    Rep Power
    0

    Default Re: Thread/method call analysis

    Isn`t that your task to make some debug messages to the code? Just wondering...

  3. #3
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default Re: Thread/method call analysis

    I'm thinking it should be possible to prove, by analyzing the structure of a program, that a particular method will only be called in a particular thread, or to show that it may be called from more than one thread and alert the programmer if the method is not thread-safe. If it is possible, I'll be surprised if the tool doesn't exist. And if it's not possible, I'd like to understand why, just out of curiosity.
    Get in the habit of using standard Java naming conventions!

  4. #4
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    131
    Rep Power
    0

    Default Re: Thread/method call analysis

    How about an interface with the desired function, an abstract class that implements it, and a container class with singleton design? You can pass the abstract class in a method, call the function by implementing it on the fly. I think that if It`s singeton you wont need a hasmap or static factory for threads.
    Foo.java
    Java Code:
    public interface Foo() {
       //your method
    }
    FooFactory.java
    Java Code:
    public class FooFactory {
          private static Map<String, CallFoo> threads = new HashMap<String, CallFoo>();
    
         public abstract class CallFoo implements Foo {
               private static CallFoo myInstance; //if singleton
               public static CallFoo init(String name, CallFoo inst); 
           }
         
        // more methods for static factory
    I think something like that approach will satisfy what you desire.

  5. #5
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    131
    Rep Power
    0

    Default Re: Thread/method call analysis

    How about an interface with the desired function, an abstract class that implements it, and a container class with singleton design? You can pass the abstract class in a method, call the function by implementing it on the fly. I think that if It`s singeton you wont need a hasmap or static factory for threads.
    Foo.java
    Java Code:
    public interface Foo() {
       //your method
    }
    FooFactory.java
    Java Code:
    public class FooFactory {
          private static Map<String, CallFoo> threads = new HashMap<String, CallFoo>();
    
         public abstract class CallFoo implements Foo {
               private static CallFoo myInstance; //if singleton
               public static CallFoo init(String name, CallFoo inst); 
           }
         
        // more methods for static factory
    I think something like that approach will satisfy what you desire.

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default Re: Thread/method call analysis

    I don't see how that's even remotely related to my question. Did you intend that reply for another thread?
    Get in the habit of using standard Java naming conventions!

  7. #7
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default Re: Thread/method call analysis

    I found a SO discussion started by someone who basically had the same idea. The keywords are static analysis. java - Static Thread Analysis: Good idea? - Stack Overflow
    Get in the habit of using standard Java naming conventions!

  8. #8
    heatblazer is offline Senior Member
    Join Date
    Nov 2012
    Posts
    131
    Rep Power
    0

    Default Re: Thread/method call analysis

    Sorry, can`t even delete it and it`s double post... Why it happens that way - I have no idea.

  9. #9
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default Re: Thread/method call analysis

    Lately the forums have been asking me to confirm that I want to "leave the page" when I post a reply. If I say no, the reply is actually posted anyway, but it doesn't appear so unless I reload the page. I've double-posted a couple times because I wasn't paying attention to that.
    Get in the habit of using standard Java naming conventions!

Similar Threads

  1. Block thread until callback method has been called by other thread
    By James2000 in forum Threads and Synchronization
    Replies: 4
    Last Post: 05-11-2012, 09:46 PM
  2. call a thread knowing its ID
    By cucucur in forum Threads and Synchronization
    Replies: 1
    Last Post: 07-05-2011, 12:14 AM
  3. Trigger main thread method from secondary thread?
    By DigitalMan in forum Threads and Synchronization
    Replies: 8
    Last Post: 01-26-2010, 02:13 AM
  4. cannot call private method from static method
    By jon80 in forum New To Java
    Replies: 3
    Last Post: 05-07-2008, 08:37 AM
  5. Replies: 0
    Last Post: 01-28-2008, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •