Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a queue for ws.sendMessage when async=true #13

Open
soygul opened this issue Apr 12, 2016 · 1 comment
Open

Use a queue for ws.sendMessage when async=true #13

soygul opened this issue Apr 12, 2016 · 1 comment

Comments

@soygul
Copy link
Member

soygul commented Apr 12, 2016

As ws.sendMessage will throw if called from another thread when busy writing stuff. Also it is a waste to create a thread per request.

@soygul
Copy link
Member Author

soygul commented Apr 13, 2016

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/ExecutorService.html

https://aws.amazon.com/articles/Java/5496117154196801

  • Also add ability to execute callbacks on main (UI) thread with a constructor switch.
  • Make it possible for user to supply their own ExecutorService.

Callback Execution

Using AsyncHandler callbacks is ideal for updating a UI with the result of an operation. Keep in mind though that your implementation of AsyncHandler is executed inside the thread pool owned by the asynchronous client. Short, quickly executed code is most appropriate inside your AsyncHandler implementation. Long running or blocking code inside the AsyncHandler implementation can cause contention for the thread pool used by the asynchronous client and can prevent the client from being able to execute requests. If you have a long-running task that needs to begin from a callback, then simply have the callback run the task in a new thread or another thread pool managed by your application.

Thread Pool Configuration

The asynchronous clients in the SDK provide a default thread pool that should work for most applications, but you are also free to supply your own ExecutorService to the asynchronous clients if you want more control over how the thread pools are managed. For example, you could provide your own ExecutorService that uses a custom ThreadFactory to control how threads in the pool are named or to log additional information about thread usage.

Amazon S3 Asynchronous Access

The TransferManager class in the SDK offers asynchronous support for working with the Amazon Simple Storage Service (Amazon S3). The TransferManager manages asynchronous uploads and downloads, provides detailed progress reporting on transfers, and supports callbacks into different events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant