Create Infinite number of Threads w/unique names, how do I kill/stop one?
I am new to Java, so please excuse my code if it is not moving and profound :0)
I'm just glad it 'works'!! no, really!!
Problem:
I use the below piece of code to create 100's of
timers(threads)..all with different names and different
sleep values.
I need to add the ability to 'kill'/'stop' a specific timer.
How do I reference it?
How do I write the code so I 'kill'/'stop' the right one?
Can I do it based on the timers name?
I am aware that I need to add
while (condition) {
in the run method....I'm just a little
confused about how I change the
condition for a specific thread.
My java code:
1. create a thread (I issue it a name and a 'sleep' time)
2. when the thread wakes up, it:
(a) makes a call to the database and executes a
database procedure (the timer name is passed
in as a variable to the database procedure)
Any help is appreciated!
------1. BEGIN-----Create a new Thread----------------------------------------------
public void StartThread (String thisTimerName, int thisInterval) {
new SimpleThread(thisTimerName, thisInterval).start();
-------1. END----------------------------------------------------------------------------------
-------2. BEGIN-----Code that creates and starts the new Thread---------------
public SimpleThread(String str, int newInterval ) {
super(str);
Interval = newInterval;
public void run() {
try {
sleep(Interval);
catch (InterruptedException e) {
TimerName = getName();
insertIntoTimers_Expired(TimerName); //this method makes a connection
//to the db, and calls a database
//procedure passing in the timers name
--------2. END ------------------------------------------------------------------------------
warnerja-
first, thanks for a reply!!
Q:
how would I correlate the timer I want to 'kill/stop' with it's assigned 'object reference'?
Say, for example, I create 4 timers:
LindasTimer, 2000
JimsTimer, 43000
SallysTimer, 8000
JimsTimer, 75000
Now, a little while later, I decide I want to 'kill/stop' JimsTimer(75000) before it expires/wakes up from sleep.
Thanks!
Similar Messages
-
The checkboxes are named 1a, 1b, 1c, 2a, 2b, 2c, etc.. up to 27a, 27b... I could add the word "bed" to the beginning of each name if it helps.
I want to create a text field that will update the count every time a box is checked or unchecked.
ThanksIt would be better to add "bed." instead, so that the field names are "bed.1a", "bed.1b", ..."bed.27b". You can then easily get an array of all of the "bed" fields, check each one, and increment a counter. The custom calculate script for the text field could be something like:
// Custom calculate script
(function () {
// Get an array of the bed fields
var fa = getField("bed").getArray();
// Initialize counter
var sum = 0;
// Loop through the fields and update counter
for (var i = 0; i < fa.length; i += 1) {
sum += fa[i].value !== "Off" ? 1 : 0;
// Set this field's value to the sum
event.value = sum; -
My scenario. I have been asked to create a series of content types to manage Report requests. A Report Base content type to be the parent, then three content types to extend that base to a Report Crystal, Report SSRS and Report SSIS. These top level
reports collect data once. Once an instance of the "Report Crystal" content type has been created the Report Writer needs to fill out another content type "Report DataSource" related by the ID of the parent to track any
stored procedures used in the report, what database\s does it hit... Here is where I am lost on the how to fill out related lists. Do I add a calculated column that attaches the report ID the a URL? e.g. ..ReportDatasource/newform.aspx?ReportID=1 which will
then show me the form. Or has this changed in 2013. I am reverse engineering some 2007 code to try to figure this out.
The next step after that hurdle is, when the report writer has completed each data source entry, a workflow generates and email with links to a "Change Request" form. There would be one created for each row in the Report Datasource. The
DBA would have to evaluate each "Change Request" and either Pass or Fail each one. This Pass\Fail parameter and a description would get recorded in a "Change Result Log".
I am wondering if a workflow replace the need for calculated columns or at least some. I think I have to have a calculated column in the initial "Report Crystal" column to fire off creating the first "Report DataSource" entry. And
then a calculated column on that to give the option of adding another entry into the "Report DataSource" list if there are multiple procedures for the report. But if the report writer sets a column in the "Report DataSource" as Ready
For Review" a workflow should generate the Change Request.
The flow is kind of set in stone but the structure is not. A very high level few of the data pointsHi Developer_46038,
if for example all the properties and object are stated as list, i think there is a tool that overcome cross list.
http://listrollup.codeplex.com/
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/13a51be5-4007-46e8-bbb2-5e04320dfebd/cross-list-webpart?forum=sharepointcustomizationlegacy
you can also using dataview webpart to show the cross lists:
http://office.microsoft.com/en-us/sharepoint-designer-help/create-a-data-view-HA010094804.aspx
http://office.microsoft.com/en-us/sharepoint-designer-help/connect-two-data-views-HA010169133.aspx
3rd party: http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2009/03/11/relational-database-capabilities-for-sharepoint-lists-cross-list-web-part.aspx
but i am not quite sure how crystal report will do, if you can make the crystal report as also list, i think its possible,
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/8247edf5-dee8-49d8-b7ee-9e49bfd97b9b/crystal-report-in-sharepoint-2010-webpart?forum=sharepointdevelopmentprevious
Regards,
Aries
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. -
Creating Multiple Number Range
Hi
I am required to create strings of the following format: XXXXYYYYY. A customized program will read in a string of 4 characters (XXXX) and generate a running number (YYYYY) for it. Every unique XXXX has its own running number range. The strings XXXX are stored in the database. More XXXX could be added to the database in the future.
For example,
TA0100001,TA0100002....
SB0200001...
SB0300001...
Is there a function to create the number ranges? Any advice on how I should approach this problem? Thanks!Hi,
I will suggest two idea's for the same.
Create one number range object for YYYYY and then append it to XXXX that is there in database, but here the number of strings that you can generate are limited.
Another Idea is to create say 5 Nmber range objects.
And have it like if XXXX is in range1 to range 2 use Number range object1 to get YYYYY.
And if XXXX is in range 2 to range 3 then use number range object2 (Or interval 2 of the same number range object 1 that is if you want only one number range object and have 5 intervals instead of 5 number range objects.) to get YYYYY. With this you will more options for generating the required XXXXYYYYY.
Transaction for creating number ranges is SNRO.
Regards,
Sesh -
Thread: How to tell when the thread is finished AND how to kill it?
Hi there,
I have a thread that runs in the background and does this:
class MyThread implements Runnable
public void run()
Stopper stopper = new Stopper();
//do something that takes some time
stopper.stop();
System.out.println("total time "+stopper.getTime());
}this works fine (I have a swing gui where I click a button and this thread runs and it's ok. PROBLEM IS, when I click the button again (to re-activate the thread) it seems that the stopper is not null but still counting the time (I was under the impression that ...= new Stopper() will create a new object type Stopper).
so -
1. How can I tell when thread is finished?
2. How do I kill this thread once it is finished?
the invocation:
public void actionPerformed(ActionEvent arg0)
Thread t = new Thread( new MyThread());
t.start();
}THANK YOU!You have not posted to code for Stopper, so it's impossible to reason about that
1. How can I tell when thread is finished?
Use Thread.Join() or Thread.isAlive()
2. How do I kill this thread once it is finished?
You can't and you don't. Just let the method the thread is running exit normally. Sometimes that means putting in a boolean variable to control a loop, and then exiting when the boolean is false.
Another thought - you could set the thread as a Daemon thread - when you don't have any non-daemon threads running, java will exit. -
Create multiple instances of same class but with unique names
Hi,
I'm creating an IM application in Java.
So far I can click on a user and create a chat session, using my chatWindow class. But this means I can only create one chatWindow class, called 'chat'. How can I get the application to dynamically make new instances of this class with unique names, for examples chatWindowUser1, chatWindowUser2.
Below is some code utlising the Openfire Smack API but hopefully the principle is the clear.
private void chatButtonActionPerformed(java.awt.event.ActionEvent evt) {
int selectedUserIndex = rosterList.getSelectedIndex();
String selectedUser = rostAry[selectedUserIndex].getUser();
System.out.println("Chat with: " + selectedUser);
if (chatBox == null) {
JFrame mainFrame = CommsTestApp.getApplication().getMainFrame();
chatBox = new CommsTestChatBox(mainFrame,conn,selectedUser);
chatBox.setLocationRelativeTo(mainFrame);
CommsTestApp.getApplication().show(chatBox);
}yes, an array would work fine, just realize that by using an array, you're setting an upper bound on the number of windows you can have open.
As for unique names, if you mean unique variable name, you don't need one. The array index serves to uniquely identify each instance. If you mean unique title for the window, set that however you want (username, index in array, randomly generated string, etc.). It's just a property of the window object. -
Move files and create unique name something wrong with my script
Can you see where I might be going wrong here?
Just trying to create a unique name if something exists.
In English.
Move file to the destinationFolder
Item exists in destinationFolder > Move file in the destination folder to the fake Trash > If it exists in fakeTrash too then give it a new name an ending of_a.psd then out it in the trash
Once thats done move start file to the destination folder.
Currently when the file exists in the destination folder and in the trash, I get the prompt then the error
error "System Events got an error: Can’t get disk item \"NN_FR10WW06290PK3LE.psd\"." number -1728 from disk item "NN_FR10WW06290PK3LE.psd"
set fileMatrix to {¬
{folderName:"BHS", prefixes:{"BH", "SM", "AL"}}, ¬
{folderName:"Bu", prefixes:{"BU"}}, ¬
{folderName:"Da", prefixes:{"ES"}}, ¬
{folderName:"Di", prefixes:{"DV"}}, ¬
{folderName:"Do", prefixes:{"DJ", "RA"}}, ¬
{folderName:"In", prefixes:{"GT", "CC"}}, ¬
{folderName:"Fr", prefixes:{"FR"}}, ¬
{folderName:"No", prefixes:{"NN"}}, ¬
{folderName:"Ma", prefixes:{"MA", "MF", "FI", "MC", "MH", "MB"}}, ¬
{folderName:"Pr", prefixes:{"PR"}}, ¬
{folderName:"To", prefixes:{"TM15", "TM11", "TM17"}}, ¬
{folderName:"Wa", prefixes:{"WA"}}, ¬
{folderName:"Se", prefixes:{"SE"}}}
tell application "Finder"
set theHotFolder to folder "Hal 9000:Users:matthew:Pictures:HotFolderDone"
set foldericon to folder "Hal 9000:Users:matthew:Pictures:Icons:Rejected Folder Done"
set fakeTrash to folder "Hal 9000:Users:matthew:FakeTrash"
---here
repeat with matrixItem in fileMatrix -- look for folder
set destinationFolder to (folders of desktop whose name starts with folderName of matrixItem)
if destinationFolder is not {} then -- found one
set destinationFolder to first item of destinationFolder -- only one destination
set theFolderName to name of destinationFolder
repeat with aPrefix in prefixes of matrixItem -- look for files
set theFiles to (files of theHotFolder whose namestarts with aPrefix) as alias list
if theFiles is not {} then repeat with startFile intheFiles -- move files
try
move startFile to destinationFolder
on error
activate
display dialog "File “" & (name ofstartFile) & "” already exists in folder “" & theFolderName & "”. Do you want to replace it?"buttons {"Don't replace", "Replace"} default button 2 with icon 1
if button returned of result is "Stop"then
if (count theLastFolder) is 0 thendelete theLastFolder
return
else if button returned of result is"Replace" then
set fileName to get name ofstartFile
if exists file fileName indestinationFolder then ¬
try
--next line moves existing file to the faketrash
move file fileName of destinationFolder to fakeTrash
move file startFile to destinationFolder
--if it already exists in fake trash give it a new name then move that file to fake trash
on error errmess numbererrnum -- oops (should probably check for a specific error number)
log "Error " & errnum& " moving file: " &errmess
set newName to mygetUniqueName(fileName,fakeTrash)
set name of fileNameto "this is a unique name"-- or whatever
set name of fileNameto newName
--Now move the renamed file to the fake trash
move file fileName to fakeTrash
--now move the startfile to destination folder
move file startFile to destinationFolder
end try
else -- "Don't replace"
if not (exists folder "Hal 9000:Users:matthew:Desktop:Rejected Folder Done") then
set theLastFolder toduplicate foldericonto desktop
else
set theLastFolder to folder"Hal 9000:Users:matthew:Desktop:Rejected Folder Done"
end if
delay 0.5
move startFile to theLastFolder with replacing
end if
end try
end repeat
end repeat
end if
end repeat
try
if (count theLastFolder) is 0 then delete theLastFolder
end try
end tell
to getUniqueName(someFile, someFolder)
check if someFile exists in someFolder, creating a new unique file name (if needed) by adding a suffix
parameters - someFile [mixed]: a source file path
someFolder [mixed]: a folder to check
returns [list]: a unique file name and extension
set {counter, suffixes, divider} to {0, "abcdefghijklmnopqrstuvwxyz", "_"}
set someFile to someFile as text -- System Events will use both Finder and POSIX text
tell application "System Events" to tell disk item someFile to set{theName, theExtension} to {name, name extension}
if theExtension is not "" then set theExtension to "." & theExtension
set theName to text 1 thru -((length of theExtension) + 1) of theName -- just the name part
set newName to theName & theExtension
tell application "System Events" to tell (get name of files of folder(someFolder as text))
repeat while it contains newName
set counter to counter + 1 -- hopefully there aren't more than 26 duplicates (numbers are easier)
set newName to theName & divider & (item counter ofsuffixes) & theExtension
end repeat
end tell
return newName
end getUniqueNameThere are numerous errors in your script, and it's a large script so there might be more, but these are the standouts for me:
At line 48 you:
set fileName to get name of startFile
which is fair enough - you then use this to see if the file already exists in the destinationFolder. However, if it does the logic about how to deal with that is flawed.
At line 56 you catch the error:
on error errmess number errnum -- oops (should probably check for a specific error number)
log "Error " & errnum & " moving file: " & errmess
set newName to my getUniqueName(fileName, fakeTrash)
set name of fileName to "this is a unique name" -- or whatever
set name of fileName to newName
--Now move the renamed file to the fake trash
move file fileName to fakeTrash
--now move the startfile to destination folder
move file startFile to destinationFolder
end try
so let's focus on that.
56: catch the error
57: log the error
58: generate a new unique filename
59: change the name of fileName to some other string
Hang on, wait a minute.... we already ascertained that at line 48 you defined fileName as a string object that indicates the name of the file. This is just a string. It's no longer associated with the original file... it's just a list of characters. Consequently you cannot set the 'name' of a string, hence your script is doomed to fail.
Instead, what I think you want to do is set the name of the startFile to the unique string. Files have filenames, and therefore you can set the name.
You have a similar problem on line 64 where you try to 'move file filename to fakeTrash'. fileName is just a string of characters. It isn't enough to identify a file - let's say the file name is 'some.psd'. You're asking AppleScript to move file some.psd to the trash. The question is which some.psd? The one on the desktop? in your home directory? maybe on the root of the volume? or maybe it should search your drive to find any/all files with that name? nope. None of the above. You can't just reference a file by name without identifying where that file is. So you probably want to 'move file fileName of destinationFolder...'
There may be other problems, but they're likely to be related - all issues with object classes (e.g. files vs. strings), or not being specific about which object you want.
As I said before, though, I might be way off - you don't say where the error is triggered to make it easy to narrow down the problem. Usually AppleScript will highlight the line that triggered an error. Knowing what that line is would help a lot. -
Error message when trying to create a unique name
Why do I keep getting an Error message when trying to create a unique name for a location on your site. I am simply looking to use your free 2GB space to store some pics and vids but keep getting an error message.
How come Leopard let me use the WGM in standard mode?
While SA complains that it won't work in Standard Configuration, WGM does not. There is some fault in the logic of this for which I don't have an explanation.
If I want to get control on Dock, selection of Home folder, config of Proxy... which I think are basic things, do I really need the advanced mode?
If you wish to have complete control of all client settings, yes. There really is no disadvantage of using an Advanced configuration other than the learning curve.
So if I switch to advanced mode, there is good chance I won't get this error message anymore, right?
Yes. -
When I create a text message from my contact on my iphone 5, the contacts mobile number appears and not there name. But when they respond to my text, is shows up as a new text message with there name. How do I fix this?
Double click the home button and swipe up the messages app to stop it, then open the app again. This pretty much completely stops the process and freshly opens it again, resolving problems at times. I have had this happen before as well on my iPad, I get a banner, check messages, and nothing new is there.
If that doesn't work, close the app like suggested above, but then restart the phone by holding down the home and lock button for 10-15 seconds until the apple logo appears. -
How to find out the number of threads created under java vm at runtime
our application seems to have hit the max number of threads that can be created under vm and the vm will just hang after that. that behavior seems to be consistent from an article that I read earlier.
I wonder any way that java app can find out the number of threads currently created under vm?
thanks in advance!If you are not starting an extra thread group you can use the Thread.activeCount method. But this willnot return all the threads, as there are some jvm threads, i.e. garbage collector. Also if you are running on a Unix type operating system then you can send a signal to the jvm to give you a thread dump, i think the signal is sighup.
If the application is hanging i would of thought that you have a deadlock situation rather then the JVM not being able to create new threads, roughly how many threads should be running ?? -
Limiting the number of threads that are created
I am trying to write a web crawler as a way of learning about multi-threading and I have hit a stumbling block (probably my design). The way the application I have started works is that I provide a single URL, which is passed to a thread and that thread then parses the web page building a list of links (If the links are not already held in a 'visited' list then they are saved in a list in the Runnable object that is parsing the html page).
When the page has been parsed the list of links are then passed to a method in a Utilities class that creates a new group of threads, 1 for each link and each of these threads then does the same thing. The problem I have is that as more and more links are captured more and more threads are created eventually I either get a out of memory exception or I get an operating system 'cannot create native thread' message. I am not sure if the threads are staying in memory after they have done their tasks, I am not sure why I am running out of memory so quickly.
What I would like to try and do is to set a limit for the maximum number of threads created and then only create new threads if the limit is not breached. If someone could point me in the right direction that would be good, I have googled around but cant find an example of what I want to do.
ThanksThanks for that, that has given me a lot to read up on and I can already see where I went wrong.... I think implementing a thread pool and also a work queue is probably the way I will go from now on.
-
Create a temp file with unique name?
Hi all,
I need to create a temporary IResource in a KM repository. Is there any equivalent to the java.io.File.createTempFile() method to create a IResource with a unique name that isn't already there?
Thanks for your help,
MarkusHi Markus,
AFAIK there is no such method.
However, you can implement it yourself by using a simple rule,
such as to concat a timestamp ((new Date()).getTime()) to the created resource's name.
For an even more robust rule, you can also concat the creator's login-name.
Hope that helps,
Yoav. -
Maximum number of threads can be created in solari
Dear All,
This is Amarnath.E, I'm working on high-end server program. As per my requirement i have to create many threads in my program.
1.Is there any limitation in solaris on creating the no. of threads?
2. If so how to increase the no. of threads that can be created?
3.Whether the No. of Threads can be created can vary based on the system configuration?
Please
ThanX in advance
Amarnath.EHello there,
I believe the previous answer is given correctly. There is no specific
kernel limit to be set. You will eventually run out of virtual address space
(after about ~3000 threads). Out of 4 GB virtual address space, kernel
base address (ie., F0000000) and beyond is reserved for kernel (except
for Ultra boxes where you can practically get almost 4GB each for
kernel and process's virtual address spaces). Thus you have about
3.75GB Sparc (3.5GB on X86 where the kernel base is E000000). It is
not recommended to reduce the thread stack size (just be sure your new
stack size will be able to handle the stack growth it needs per thread)
but, if you are sure it is safe for your purpose, this can be done as an
argument to a thread creation. Please see also manpage on thr_create.
hope this helps.
hae
Sun Developer Technical Support -
Identifying Multiple printers with unique name?
I support an office staff of 40 users that share 15 Officejet 100 L411a printers. When users connect a printer by USB, the computer will create a new printer with the default name "HP Officejet 100 Mobile L411" printer if that printer hasn't connected to that computer before. If the printer has been connected before, a new printer is not created.
Many users have multiple copies of printers all with the same printer name "HP Officejet 100 Mobile L411". The printer that is connected is highlighted; all other printers are grayed out.
My users want to know which printers they've checked out before when they pick up a printer. The users can rename the printers manually but most don't want to do that. I can rename them for the users, but that's a lot of users and a lot of printers. Either way, the next time they get a printer they haven't used before they'll get the default name.
I'd like to know if there is a way to set the printer's firmware to create a unique name when the printer is created by using the serial number or another designation I could enter.
For example, I'd like to have "HP Officejet 100 #MY1555AAQQ" or "HP OfficeJet 100 Purple #12" show up as the printer name. Is there any way to do that?Our requirement is...
Yep, had this requirement as well.
All these various user name collisions and worse is different IDs for the same person can be solved relatively easily by IdM.
But best practice is still to remove the collisions and use unique IDs. Same goes for deleting users (dont do it).
Good luck.
Cheers,
Julius -
How to create list of a View's column names and source
Using SQL 2005, 2008, and 2012
How to create list of a View's column names and source. For the following example would like to @Print something like the following. Does anyone already have some code to do this? I realize there are probably some gotchas, but the views that I am looking
at to use this follows the code snippet pattern below.
DBACCT.[Account Number]
dbo.ConvertDate(DBACDT). [Boarding Date]
DBXES.DBXES
CREATE VIEW [dbo].[v_ods_DBAL]
AS
SELECT DBACCT AS [Account Number], dbo.ConvertDate(DBACDT) AS [Boarding Date], DBXES
FROM dbo.ods_DBALThe column information can be obtained from INFORMATION_SCHEMA.COLUMNS view using logic like below
SELECT c.COLUMN_NAME,c.DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE EXISTS (SELECT 1
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_NAME = c.TABLE_NAME
AND TABLE_TYPE='VIEW')
http://technet.microsoft.com/en-us/library/ms188348.aspx
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
Maybe you are looking for
-
Does anybody know what system tables store the logs displayed in ST22 and SM37? Trying to programmatically read and display the logs. Thanks a bunch for your help.
-
Web Service Error : Unable to connect to the remote server
Hi, I encountered below errors while I run the web service in ERP 2006 system : Unable to connect to the remote server, No connection could be made because the traget machine actively refused at xxx.xxx.xxx.xxx:443 Pls kindly advise. Thanks. Edward T
-
Is there any option to maintain no of labours in routing operation wise?
Hi Experts, I want to know the no of labours used to perform one operation. So is there any way so that I can know how many labours have been performed in one operation in routing?
-
Why is my macbook air downloading so slowly?
I have the most recent OS 10.9.4. My Air is mid 2013 13". I am running google chrome and the downloads are extremely slow. They don't show up on my desktop quickly either. Safari is running a little faster, but not as fast as I think it used to.
-
Need to know how to rollback firmware - wrt54gs
Hey as you've read i have the wrt54gs v6 firmware v. 1.52.2 and have been expieriencing these internet connect drops randomly so i'd like to rollback the firmware to the original 1.02.2. I've got the .bin file for the original firmware from the stick