[377566] The server timeout timer begins at the incorrect time
[377835] The JavaDoc and implementation isn't consistent for utility method ServerUtil.setRuntimeDefaultName() - Port to WTP 3.2.5 patches
diff --git a/features/org.eclipse.wst.server_core.feature.patch/buildnotes_org.eclipse.wst.server_core.feature.patch.html b/features/org.eclipse.wst.server_core.feature.patch/buildnotes_org.eclipse.wst.server_core.feature.patch.html
index e9540d9..2766708 100644
--- a/features/org.eclipse.wst.server_core.feature.patch/buildnotes_org.eclipse.wst.server_core.feature.patch.html
+++ b/features/org.eclipse.wst.server_core.feature.patch/buildnotes_org.eclipse.wst.server_core.feature.patch.html
@@ -17,6 +17,8 @@
 <p>Bug <a href='https://bugs.eclipse.org/364482'>364482</a>. A race condition could occur in Server code</p>
 <p>Bug <a href='https://bugs.eclipse.org/370832'>370832</a>. Auto publish will not triggered for structure changes</p>
 <p>Bug <a href='https://bugs.eclipse.org/370992'>370992</a>. Extensible Server Start Jobs</p>
+<p>Bug <a href='https://bugs.eclipse.org/377566'>377566</a>. The server timeout timer begins at the incorrect time</p>
+<p>Bug <a href='https://bugs.eclipse.org/377835'>377835</a>. The JavaDoc and implementation isn't consistent for utility method ServerUtil.setRuntimeDefaultName() - Port to WTP 3.2.5 patches</p>
 
 
 </body></html>
\ No newline at end of file
diff --git a/features/org.eclipse.wst.server_core.feature.patch/feature.properties b/features/org.eclipse.wst.server_core.feature.patch/feature.properties
index ebad37a..3282694 100644
--- a/features/org.eclipse.wst.server_core.feature.patch/feature.properties
+++ b/features/org.eclipse.wst.server_core.feature.patch/feature.properties
@@ -30,6 +30,8 @@
 Bug https://bugs.eclipse.org/364482 A race condition could occur in Server code\n\
 Bug https://bugs.eclipse.org/370832 Auto publish will not triggered for structure changes\n\
 Bug https://bugs.eclipse.org/370992 Extensible Server Start Jobs\n\
+Bug https://bugs.eclipse.org/377566 The server timeout timer begins at the incorrect time\n\
+Bug https://bugs.eclipse.org/377835 The JavaDoc and implementation isn't consistent for utility method ServerUtil.setRuntimeDefaultName() - Port to WTP 3.2.5 patches\n\
 \n\
 # "copyright" property - text of the "Feature Update Copyright"
 copyright=\
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerUtil.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerUtil.java
index 30bc068..8e243a0 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerUtil.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/ServerUtil.java
@@ -1,5 +1,5 @@
 /**********************************************************************
- * Copyright (c) 2003, 2011 IBM Corporation and others.
+ * Copyright (c) 2003, 2012 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -394,7 +394,8 @@
 	 * @param suffix
 	 *          the numbering to start at for the suffix, if suffix is -1, then the no suffix name will be tried first.
 	 * @return the suffix it found no name conflicts at and is using as part of
-	 *         the default name
+	 *         the default name. If suffix passed in was -1 and the no suffix name 
+	 *         does not conflict, the suffix returned is -1
 	 */
 	public static int setRuntimeDefaultName(IRuntimeWorkingCopy runtime, int suffix) {
 		String typeName = runtime.getRuntimeType().getName();
@@ -402,16 +403,26 @@
 		String name = null;
 		if (suffix == -1) {
 			name = NLS.bind(Messages.defaultRuntimeName, typeName);
-			// Start next suffix from 2 to preserve the original behaviour before this change.
-			suffix = 2;
 		} else {
 			name = NLS.bind(Messages.defaultRuntimeName2, new String[] { typeName, suffix + "" });
 		}
 
-		while (ServerPlugin.isNameInUse(runtime.getOriginal(), name)) {
+		if (ServerPlugin.isNameInUse(runtime.getOriginal(), name)){
+			if (suffix == -1){
+				// If the no suffix name is in use, the next suffix to try is 2
+				suffix = 2;
+			}
+			else {
+				suffix++;
+			}
+			
 			name = NLS.bind(Messages.defaultRuntimeName2, new String[] { typeName, suffix + "" });
-			suffix++;
+			while (ServerPlugin.isNameInUse(runtime.getOriginal(), name)) {
+				suffix++;
+				name = NLS.bind(Messages.defaultRuntimeName2, new String[] { typeName, suffix + "" });
+			}
 		}
+		
 		runtime.setName(name);
 		return suffix;
 	}
diff --git a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Server.java b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Server.java
index bfec066..1bdaf42 100644
--- a/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Server.java
+++ b/plugins/org.eclipse.wst.server.core/servercore/org/eclipse/wst/server/core/internal/Server.java
@@ -3290,8 +3290,6 @@
 				}
 			}
 		};
-		thread.setDaemon(true);
-		thread.start();
 		
 		if (Trace.FINEST) {
 			Trace.trace(Trace.STRING_FINEST, "synchronousRestart 2");
@@ -3300,6 +3298,9 @@
 		// call the delegate restart
 		try {
 			getBehaviourDelegate(null).restart(launchMode);
+			
+			thread.setDaemon(true);
+			thread.start();
 		} catch (CoreException e) {
 			removeServerListener(listener);
 			timer.alreadyDone = true;
@@ -3435,8 +3436,6 @@
 				}
 			}
 		};
-		thread.setDaemon(true);
-		thread.start();
 	
 		if (Trace.FINEST) {
 			Trace.trace(Trace.STRING_FINEST, "synchronousStart 2");
@@ -3445,9 +3444,11 @@
 		// start the server
 		try {
 			startImpl2(launchMode, monitor);
+			
+			thread.setDaemon(true);
+			thread.start();			
 		} catch (CoreException e) {
 			removeServerListener(listener);
-			timer.alreadyDone = true;
 			return e.getStatus();
 		}
 		if (monitor.isCanceled()) {
@@ -3561,11 +3562,23 @@
 		final Timer timer = new Timer();
 		
 		final int serverTimeout = getStopTimeout() * 1000;
+		Thread thread = null;
 		if (serverTimeout > 0) {
-			Thread thread = new Thread("Server Stop Timeout") {
+			thread = new Thread("Server Stop Timeout") {
 				public void run() {
-					try {
-						Thread.sleep(serverTimeout);
+					try {					
+						int totalTimeout = serverTimeout;
+						if (totalTimeout < 0)
+							totalTimeout = 1;
+						
+						int retryPeriod = 1000;						
+						
+						while (totalTimeout > 0 && !timer.alreadyDone){
+							Thread.sleep(retryPeriod);
+							if (serverTimeout > 0)
+								totalTimeout -= retryPeriod;
+						}
+
 						if (!timer.alreadyDone) {
 							timer.timeout = true;
 							// notify waiter
@@ -3584,13 +3597,16 @@
 					}
 				}
 			};
-			thread.setDaemon(true);
-			thread.start();
 		}
 		
 		// stop the server
 		stopImpl2(force);
 		
+		if (thread != null){
+			thread.setDaemon(true);
+			thread.start();
+		}
+		
 		// wait for it! wait for it!
 		synchronized (mutex) {
 			try {
@@ -3603,6 +3619,7 @@
 							"Error waiting for server stop", e);
 				}
 			}
+			timer.alreadyDone = true;
 		}
 		removeServerListener(listener);