/* (non-Javadoc)
@see com.ibm.ws.logging.hpel.LogRepositoryManager#startNewFile(long)
Modification to this method to queue requests so that the ORB calls are made when the thread is not holding crucial locks
356681
public synchronized File startNewFile(long timestamp) {
		if (debugLogger.isLoggable(Level.FINE) && LogRepositoryBaseImpl.isDebugEnabled()) {
			debugLogger.logp(Level.FINE, thisClass, "startNewFile", "unsentEmpty: "+unsentFileNotifications.isEmpty()+
				" tstamp: "+timestamp+" Tp: "+managedType+" subProcCommAgent: "+ivSubProcessCommAgent);
		}
		synchronized(unsentFileNotifications) {		// Do not make orb call while holding the LogRecordHandler
			unsentFileNotifications.add(timestamp) ;		// 671059 queue up for later notification
		}
		File file = null ;
		if (debugLogger.isLoggable(Level.FINE) && LogRepositoryBaseImpl.isDebugEnabled()) {
			debugLogger.logp(Level.FINE, thisClass, "startNewFile", "Add tstamp: "+timestamp+
				" is unsent entry: "+unsentFileNotifications.size()+" FileNm: "+"xx");
		}
		int count = 0;
		while (ivSubDirectory == null) {
			File parentDir = makeLogDirectory(timestamp, ivSuperPid);
			if (parentDir == null) {
				if (++count > FAILED_MAX_COUNT) {
					throw new RuntimeException("Failed to create instance log repository. See SystemOut.log for details.");
				}
				try {
					Thread.sleep(FAILED_WAIT_TIME);
				} catch (InterruptedException ex) {
					// Ignore it, assume that we had enough sleep.
				}
			} else {
				ivSubDirectory = new File(parentDir, getLogDirectoryName(-1, ivPid, ivProcessLabel));
			}
		}
		
		file = getLogFile(ivSubDirectory, timestamp);
			
		File dir = file.getParentFile();
		if (!AccessHelper.isDirectory(dir)) {
			AccessHelper.makeDirectories(dir);
		}
		
		// 682033 look at servant subDirectory and
		if (ivMaxListSize >= 0) {
			createdFiles.add(file);
			if (createdFiles.size() > ivMaxListSize) {
				AccessHelper.deleteFile(createdFiles.remove(0));
			}
		}
		// End of 682033 logic
		return file;
	}
509806
def _restart(self, submit=True):
        
        self.set_status(self.S_READY, msg="Restarted on %s" % time.asctime())

        # Increase the counter.
        self.num_restarts += 1
        self.history.info("Restarted, num_restarts %d" % self.num_restarts)

        # Reset datetimes
        self.datetimes.reset()

        # Remove the lock file
        self.start_lockfile.remove()

        if submit:
            # Relaunch the task.
            fired = self.start()
            if not fired: self.history.warning("Restart failed")
        else:
            fired = False

        return fired
545347
private void waitForNextRecord(long startingTime, long timestamp) {
        if(mFirstTimestamp == 0) {
            mFirstTimestamp = timestamp;
            Log.d(TAG, "Storing " + timestamp + " as the first " +
                    "timestamp of the trace file");
        }
        long targetTime = startingTime + (timestamp - mFirstTimestamp);
        long sleepDuration = Math.max(targetTime - System.currentTimeMillis(), 0);
        try {
            Thread.sleep(sleepDuration);
        } catch(InterruptedException e) {}
    }
1125189
protected void onStartup(ServletContext servletContext, Class<?> appConfig, int maxFileSize) {
    // Create the 'root' Spring application context
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.setAllowBeanDefinitionOverriding(false);
    rootContext.register(appConfig);

    // Manage the lifecycle of the root application context
    servletContext.addListener(new ContextLoaderListener(rootContext));

    // Register and map the dispatcher servlet
    DispatcherServlet dispatcherServlet = new DispatcherServlet(rootContext);
    dispatcherServlet.setDispatchOptionsRequest(true);
    // instead of throwing a 404 when a handler is not found allow for custom handling
    dispatcherServlet.setThrowExceptionIfNoHandlerFound(true);

    ServletRegistration.Dynamic dispatcherServletRegistration =
        servletContext.addServlet("dispatcher", dispatcherServlet);
    if (dispatcherServletRegistration == null) {
      LOG.warn(
          "ServletContext already contains a complete ServletRegistration for servlet 'dispatcher'");
    } else {
      final long maxSize = (long) maxFileSize * MB;
      dispatcherServletRegistration.addMapping("/");
      dispatcherServletRegistration.setMultipartConfig(
          new MultipartConfigElement(null, maxSize, maxSize, FILE_SIZE_THRESHOLD));
      dispatcherServletRegistration.setAsyncSupported(true);
    }

    // add filters
    Dynamic browserDetectionFiler =
        servletContext.addFilter("browserDetectionFilter", BrowserDetectionFilter.class);
    browserDetectionFiler.setAsyncSupported(true);
    browserDetectionFiler.addMappingForUrlPatterns(
        EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC), false, "*");

    Dynamic etagFilter = servletContext.addFilter("etagFilter", ShallowEtagHeaderFilter.class);
    etagFilter.setAsyncSupported(true);
    etagFilter.addMappingForServletNames(
        EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC), true, "dispatcher");

    // enable use of request scoped beans in FrontController
    servletContext.addListener(new RequestContextListener());

    servletContext.addListener(HttpSessionEventPublisher.class);
  }
936459
public void enqueue(String resourceFileName) throws IOException {
		File tmp = new File(path,resourceFileName);
		if(!tmp.isFile()) {
			tmp.createNewFile();
		}
	}
1264136
final void begin() {
    if (this.properties.isDateRollEnforced()) {
      final Thread thread = new Thread(this,
          "Log4J Time-based File-roll Enforcer");
      thread.setDaemon(true);
      thread.start();
      this.threadRef = thread;
    }
  }
65206
public boolean start() {
        if (!this.isTailing.compareAndSet(false, true)) {
            return false;
        }
        final boolean willReadFromEnd = this.willReadFromEnd();
        LogWatchTailingManager.LOGGER.debug("Tailer {} ignore existing file contents.", willReadFromEnd ? "will"
                : "won't");
        this.tailer = new SplitlogTailer(this.watch.getWatchedFile(), new LogWatchTailerListener(this),
                this.delayBetweenReads, this.willReadFromEnd(), this.reopenBetweenReads, this.bufferSize);
        LogWatchTailingManager.EXECUTOR.submit(this.tailer);
        final long start = System.nanoTime();
        this.tailer.waitUntilStarted();
        final long duration = System.nanoTime() - start;
        LogWatchTailingManager.LOGGER.debug("It took {} ms for the tailing to actually start.",
                TimeUnit.NANOSECONDS.toMillis(duration));
        final long iterationNum = this.numberOfTimesThatTailerWasStarted.incrementAndGet();
        LogWatchTailingManager.LOGGER.info("Tailing #{} started for {}.", iterationNum, this.watch);
        return true;
    }
752207
@Override
    public void onNewFolder(@NonNull String name) {
        AsyncTask<String, Void, FtpFile> task = new AsyncTask<String, Void, FtpFile>() {

            @Override
            protected FtpFile doInBackground(String... names) {
                FtpFile result = null;
                if (names.length > 0) {
                    result = onNewFolderAsync(names[0]);
                }
                return result;
            }

            @Override
            protected void onPostExecute(FtpFile folder) {
                if (folder != null) {
                    refresh(folder);
                } else {
                    Toast.makeText(getContext(), R.string.nnf_create_folder_error, Toast.LENGTH_SHORT).show();
                }
            }
        };
        task.execute(name);
    }
704148
public boolean createNewFile() throws IOException
  {
    synchronized (LOCK) {
      if (! exists()) {
        clearStatusCache();
        WriteStreamOld s = openWrite();
        s.close();
        return true;
      }
    }

    return false;
  }
1028461
private String startAsyncOperation() throws IOException, ClassNotFoundException, InterruptedException, SQLException {
		System.out.println("Executor started ...");
		
		// do some sync work - eg. check for latest version:
		HttpsURLConnection url = (HttpsURLConnection) new URL("https://github.com/Dynatrace/OneAgent-SDK-for-Java/releases/latest").openConnection();

		// we expect redirect to latest release url:
		url.setInstanceFollowRedirects(false);
		int responseStatus = url.getResponseCode();
		if (responseStatus != 302) {
			System.out.println("no redirect retrieved!");
			return null;
		}
		
		// e. g.: https://github.com/Dynatrace/OneAgent-SDK-for-Java/releases/tag/v1.0.3
		String location = url.getHeaderField("Location");
		String latestVersion = location.substring(location.lastIndexOf('/') + 1);
		
		// tag this request using the found SDK version:
		oneAgentSdk.addCustomRequestAttribute("oneagentsdk.java.version", latestVersion);

		// download the big release archive asynchronously ... 
		UrlDownloadItem asyncWorkItem = new UrlDownloadItem(
				"https://github.com/Dynatrace/OneAgent-SDK-for-Java/archive/" + latestVersion + ".zip", 
				oneAgentSdk.createInProcessLink());
		blockingQueue.put(asyncWorkItem);
		
		return latestVersion;
	}
1064251
private void openNewPartIfNecessary(long sizeThreshold) throws IOException {
		final long fileLength = fileStream.getPos();
		if (fileLength >= sizeThreshold) {
			lock();
			try {
				uploadCurrentAndOpenNewPart(fileLength);
			} finally {
				unlock();
			}
		}
	}
944435
public void refresh() throws IOException
    {
        if (Files.exists(file))
        {
            fine("%s exist", file);
            writeLock.lock();
            try
            {
                finer("start update(%s)", file);
                update(file);
                finer("end update(%s)", file);
            }
            finally
            {
                writeLock.unlock();
            }
            FileTime lmt = Files.getLastModifiedTime(file);
            if (thread == null && lmt.toMillis()+expires < System.currentTimeMillis())
            {
                thread = new Thread(this, url.toString());
                thread.setDaemon(true);
                thread.start();
                fine("started thread for %s", url);
            }
        }
        else
        {
            fine("%s doesn't exist", file);
            run();
        }
    }
156367
@Override
    public synchronized void onFileCreate(File file) {
        final Set<DetectedWebJar> listOfDetectedWebJarLib = isWebJar(file);
        if (listOfDetectedWebJarLib != null) {
            JarFile jar = null;
            try {
                jar = new JarFile(file);
                List<FileWebJarLib> installed = new ArrayList<>();
                for (DetectedWebJar detected : listOfDetectedWebJarLib) {
                    FileWebJarLib lib = expand(detected, jar);
                    if (lib != null) {
                        libs.add(lib);
                        installed.add(lib);
                        LOGGER.info("{} unpacked to {}", lib.name, lib.root.getAbsolutePath());
                    }
                }
                controller.addWebJarLibs(installed);
            } catch (IOException e) {
                LOGGER.error("Cannot open the jar file {}", file.getAbsolutePath(), e);
            } finally {
                IOUtils.closeQuietly(jar);
            }

        }
    }
1163231
private void startupInstance() throws IOException {
        assert (m_blockPathMap.isEmpty());
        try {
            clearSwapDir();
        }
        catch (Exception e) {
            throw new IOException("Unable to clear large query swap directory: " + e.getMessage());
        }
    }
839782
public synchronized void start()
    {
        _buffer=new ByteArrayISO8859Writer(_bufferSize);
        _reopen=false;
        if (_started)
            return;
        
        if (_out==null && _filename!=null)
        {
            try
            {
                RolloverFileOutputStream rfos=
                    new RolloverFileOutputStream(_filename,_append,_retainDays);
                _out=rfos;
            }
            catch(IOException e){e.printStackTrace();}   
        }

        if (_out==null)
            _out=LogStream.STDERR_STREAM;
        
        _started=true;
    }
813528
@Override
  final void startImpl(Optional<String> name) {
    this.executorService =
        ExecutorsUtils.loggingDecorator(Executors.newScheduledThreadPool(0,
                ExecutorsUtils.newDaemonThreadFactory(Optional.of(LOGGER), name)));
  }
629906
public File getNewFile(final RelativeResource relativeFile)
		throws IOException {
		File file = getResource(relativeFile).getFile();
		deleteOldFile(file);
		return file;
	}