我不得不将以下法典模式移至 Java。 我很想知道,在 Java与任何图书馆或没有:
async def call_external_service(user):
async with session.get(url, headers=headers) as response:
response = await response.json()
# extract some field from the response
country = response.json()[ country ]
print(country)
async def get_countries(users):
tasks = [asyncio.ensure_future(call_external_service(user)) for user in users]
await asyncio.gather(*tasks, return_exceptions=True)
users = list()
with open("users.txt", "r") as f:
for line in f.readlines():
users.append(line.strip(
))
asyncio.run(get_countries(users))
增 编