mpetazzoni / ttorrent

BitTorrent Java library with tracker and download client
http://mpetazzoni.github.com/ttorrent/
Apache License 2.0
1.38k stars 502 forks source link

TTORRENT_HASHING_THREADS configuration read incorrectly #221

Closed viswamy closed 5 years ago

viswamy commented 5 years ago

The static variables and blocks are executed in order they are specified in the java file. The hashing executor is created before the configuration is read from the system environment and therefore this configuration is never reflected in the code.

https://github.com/mpetazzoni/ttorrent/blob/db52f13ba709b26d9605d7ef18739cdaa7c5fc6d/common/src/main/java/com/turn/ttorrent/common/TorrentCreator.java#L364

mpetazzoni commented 5 years ago

@vswamy thanks for reporting! Do you think you'd be able to provide a PR with a fix? I'd be happy to review it and merge it!

Dead-off commented 5 years ago

@vswamy Thanks you, i moved this code before creating executor. So i think now it works correctly

viswamy commented 5 years ago

So fast. Thanks @Dead-off

I have another concern related to how the number of threads are created. The Executor is created when the class get's loaded by jvm and usually happens when the application is booting up that is, when most of the processors (cpu) is free.

Looking at the documentation of availableProcessors: ` /**

Should we be resetting the executor as the time goes by to reflect the CPU capacity available?

Dead-off commented 5 years ago

I want to create new class for creating torrent metadata. I don't like so many static classes and fields, it's bad style. I will try to create new api soon and resolve this problem there

viswamy commented 5 years ago

Cool.. Thanks a lot

mpetazzoni commented 5 years ago

Thanks @Dead-off; closing this issue now then.