Thread information of intercepting method Spring AOP - multithreading

Is there a way to find out the thread information of the method which AOP intercepts, using some sort of around advice? E.g if my around advice is intercepting a login method, is there a way to obtain the information of the thread which is actually running the login method through classes like joinpointcut etc.? Thanks in advance.

use:
Thread.currentThread();
The static method java.lang.Thread.currentThread() returns a reference to the currently executing thread object.

Related

how can i create a property containing a synchronized list which can updated by all threads in JMeter?

i created this list on JSR223 PreProcessor. I access to this list by all the threads but the problem is that it is not synchronized
props.put("listOfTasks", new ArrayList());
someone has any idea how to do it ? thank you
props itself is Properties which inherits from HashTable which is synchronized by nature. More information: Top 8 JMeter Java Classes You Should Be Using with Groovy
What do you store there it's totally up to you, ArrayList per se is not synchronized so you might want to use CopyOnWriteArrayList or call Collections.synchronizedList() function
It's quite hard to give a piece of advice without either seeing your code or background information like what you're trying to achieve, the safest solution from JMeter perspective is working with your list under Critical Section Controller scope, it will allow to avoid any race conditions

Where to find documentation for Thread class

In this JMeter article author is showing some examples with Thread class. He executes some specific methods for this class like: getName(), getId(). But there are no links to documentation for it.
Can someone please share a link to documentation where i can find about Thread class methods?
Google doesn't helped. The closest thing is https://jmeter.apache.org/api/org/apache/jmeter/threads/JMeterThread.html, but this isn't a class that I'm looking for (it doesn't has methods getName(), getId())
This is java's Thread class, JMeter is written in (pure) Java
A thread is a thread of execution in a program. The Java Virtual Machine allows an application to have multiple threads of execution running concurrently.
Check out these links
https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html
for example
https://www.geeksforgeeks.org/java-lang-thread-class-java/

Delphi (Indy) Threadsafe classes

Let's say I have some class, TMaster, which asa field includes a TIdTCPServer. Some method of the TMaster class is responsible for the OnExecute event of the TIdTCPServer.
Firstly, is this threadsafe and acceptible? Secondly, let's assume my class has many other private fields (Name, Date, anything...) can the OnExecute event - which is really a method INSIDE the TMaster class, write to these variables safely?
I guess I mean to ask if private fields are threadsafe in this situation?
I am really new to threading and any help will be greatly appreciated!
Thanks,
Adrian!
The way I approach this is not to have the fields used by the events belong to the TidTCPServer
owner, but define a custom TidContext descendant and add the fields to that class.
Then you simply set the ContextClass property on the server class to the type of the of your custom context. This way each Connection/Thread will get its own custom context containing its own private fields, this way there is no issue with concurrent thread access to the same fields.
if you have a list of objects that need to be accessed by the different contexts you have two options.
1) create copies the objects and store them in a private field in for each context instance
This can be done in the OnConnect Event.
2) Protect the objects from concurrent thread access using a synchroniser eg TIdCriticalSection, TMultiReadExclusiveWriteSynchronizer or semaphore,
which method you use depends on each individual situation.
if you need to manipulate any vcl components remember this can't safely be done outside the main vcl thread therefore you should create your own tidnotify decendants for this. performing this sort of operation using tidsynch can lead to deadlocks when stoping the tidtcpserver if it is in the middle of a vclsynch operation.
this is just some of what I have learned over the course of a few years using Indy.
TIdTCPServer is a multi-threaded component. No matter what you wrap it in, the OnExecute event will always be triggered in the context of worker threads, one for each connected client, so any code you put inside the handler must be thread-safe. Members of the TMaster class need adequate protection from concurrent access by multiple threads at the same time.

How can a Guava ListenableFuture<Object> wait for information from a Stack?

I have a private Stack S which is filled with objects from out-side of the class (using methods).
A ListenableFuture should read the stack and retrieve an Object from it,
but if the stack is empty it should wait for an object to be inserted to the stack and then retrieve it. I'm not sure how to implement this.
My idea was to use Wait / Notify for the ListenableFuture but is this correct logic (working with Guava)?
What other options do I have?
Thanks in advance,
Guy
ListenableFuture and Guava don't come into this at all. The way to do this is to implement the stack with LinkedBlockingDeque, have the method to add elements to the stack use addFirst, and use pollFirst(long, TimeUnit) to wait the specified amount of time for an object to get inserted.
Never use low-level concurrency tools like wait and notify if you can do the same job with library support.

Modal NSAlert from NSOperation

I have a time consuming process which runs with an NSOperation.
I now need user's choice to choose between different subprocesses.
I need to stop the process until the user respond to the question.
How can I do this from an NSOperation?
Thanks
It should just be a matter of creating an NSAlert and calling runModal on it, making sure you're on the main thread. Have you tried that?
Perhaps in the method where you are creating the NSAlert, you can have assert([NSThread isMainThread]) at the top of the method and I think that this will assure that this method get executed on the main thread. I hope this helps!

Resources