综合技术

Design for a multi-threaded REST API client

微信扫一扫,分享到朋友圈

Design for a multi-threaded REST API client
0

I am working on a program that receives search requests for a topic, makes API calls to the New York Times API to fetch articles related to the topic, and then to the Twitter API to fetch tweets mentioning the articles and finally processes the results and returns it back.

I have to make this multi-threaded. I thought about using an ExecutorService with a fixed-sized thread pool. So, every incoming search request will handled by a separate thread. I also use the Callable interface to submit tasks. The class that implements the Callable does the API processing(making & receiving API requests/responses). Finally the result is then fetched by a Future and displayed as the output. This happens for every incoming request.

Does this make sense? Or is there a better way to do this?

EDIT: I am running this on my local machine accepting data from the command line interface.

If this is a web application, it is multi-threaded by default. If it’s not – you still can deploy it on a servlet container, it would be beneficial. The thread pool is supplied by the underlying container (tomcat, for example). Each request is serviced by a separate thread.

The only things to care about:

synchronized
ThreadLocal
阅读原文...

微信扫一扫,分享到朋友圈

Design for a multi-threaded REST API client
0
Hello, buddy!

周杰伦的歌要付费听了,音乐付费爆发还有多远?

上一篇

《英雄不再 TSA》4 月 18 日推出「坏女孩」DLC 及联动内容

下一篇

评论已经被关闭。

插入图片

热门分类

往期推荐

Design for a multi-threaded REST API client

长按储存图像,分享给朋友