Hello,
jShellQueue is a queue system for jShell. It is useful in these cases:
With this example, I scan all the IP addresses of a subnetwork, but limit the number of concurrent jobs to 25 with timeout of 5 second for each command. You can try to set the concurrent job limit to 0 for unlimited threads:
Note: I recommend to declare your jShellQueue in the sub_globals, and this way have a global queue for your project.
I have attached the library, and the example. The source code is included in the example.
Enjoy
Jmon.
jShellQueue is a queue system for jShell. It is useful in these cases:
- Set the maximum number of shell commands running at the same time
- Useful when you need to run lots of commands but don't want to flood your JVM memory.
- Set a tag to your commands, and retrieve the tag when the command is executed.
- Get notified when a single job has completed or when the whole queue is finished.
With this example, I scan all the IP addresses of a subnetwork, but limit the number of concurrent jobs to 25 with timeout of 5 second for each command. You can try to set the concurrent job limit to 0 for unlimited threads:
B4X:
Sub Something
'Init the Shell queue
Dim Queue As ShellQueue
Dim ConcurrentJobs As Int = 25
Queue.Initialize(ConcurrentJobs, 5000, Me, "mtc")
For i = 0 To 255
Queue.AddToQueue("cmd.exe", _
Array("/c", "ping", $"192.168.0.${i}"$, "-n", "4"), _
"C:/Windows/System32/", _
False, _
$"192.168.0.${i}"$)
Next
Queue.StartQueue
End Sub
Sub Queue_JobCompleted(Job As ShellQueueJob)
Dim Offline As Boolean = Job.StdOut.ToLowerCase.Contains("request timed out") Or Job.StdOut.ToLowerCase.Contains("unreachable")
If Not(Offline) Then
Log($"${Job.tag} : Online"$)
Else
Log($"${Job.tag} : OFFLINE / UNREACHABLE"$)
End If
End Sub
Sub Queue_QueueFinished
Log($"Queue Finished"$)
End Sub
Note: I recommend to declare your jShellQueue in the sub_globals, and this way have a global queue for your project.
I have attached the library, and the example. The source code is included in the example.
Enjoy
Jmon.
Attachments
Last edited: