SOLVED Embedded http server and worker (background) thread lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Renat.Su · 2018-09-27 11:53 I have developed HTTP embedded server with Brook Framework. In addition to TBrookAction (offtop: actually I did not understand - its are executed  in a separate thread or in one awaiting for the queue) for user interaction via HTTP I have a background/worker thread to perform some continuous and periodical actions. This worker thread is now starting in the unit initialization section and frees (so if app is terminated by user) in finalization section. Everything works. But... I would like to have more control over the application via SSH: [auto]start, stop, restart, maybe something else. As I understand it I need to do not just the HTTP server but a daemon HTTP server. And then there is the question whether it is possible to keep the run worker thread in the initialization part of the unit or need the start and stop of processing inside a class instance TBrookHttpDaemon. But how do I do that then? ---------------------------------------------------------------------- Renat.Su · 2018-11-11 07:58 I have encountered an error when stopping the daemon. Code: [Select]Error in my_thread_global_end(): 1 threads didn't exitIt turned out that the problem was not in the worker thread but the use of the MySQL DB connector. I used one connection in a multithreaded connection. In the new version, I started using a separate MySQL connection for each thread (TBRookAction, Worker thread) and everything is fine now. ---------------------------------------------------------------------- Leledumbo · 2018-11-11 19:40 Quote from: Renat.Su on September 27, 2018, 01:53:18 pmofftop: actually I did not understand - its are executed  in a separate thread or in one awaiting for the queue By default, it runs in single process. To make every request handled as separate thread, add this code before BrookApp.Run: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i (BrookApp.Instance as TBrookHTTPApplication).Threaded := true; Quote from: Renat.Su on September 27, 2018, 01:53:18 pmI would like to have more control over the application via SSH: [auto]start, stop, restart, maybe something else. As I understand it I need to do not just the HTTP server but a daemon HTTP server. I would add protected endpoints instead of using daemon. Quote from: Renat.Su on September 27, 2018, 01:53:18 pmAnd then there is the question whether it is possible to keep the run worker thread in the initialization part of the unit or need the start and stop of processing inside a class instance TBrookHttpDaemon. But how do I do that then? Not really get this.