I am trying to run the below concurrency code: import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class TestThread { public static void main(final String[] arguments) throws InterruptedException { ExecutorService executor = Executors.newSingleThreadExecutor(); try { executor.submit(new Task()); System.out.println("Shutdown executor"); executor.shutdown(); executor.awaitTermination(5, TimeUnit.SECONDS); } catch (InterruptedException e) { System.err.println("tasks interrupted"); } finally { if (!executor.isTerminated()) { System.err.println("cancel non-finished tasks"); } executor.shutdownNow(); System.out.println("shutdown finished"); } } static class Task implements Runnable { public void run() { try { int duration = 6; System.out.println("Running Task!"); TimeUnit.SECONDS.sleep(duration); } catch (InterruptedException e) { e.printStackTrace(); } } } } and the output is : Shutdown executor Running …

Member Avatar
Member Avatar
+0 forum 3

Hi, I would linke to know what is the best way to synchronise the shared memory segment. is threads usage are also advisible whie synhcronising the shared memory segement. in what circumstances we should use threads or semaphore to synchronize the memory segment.

Member Avatar
Member Avatar
+0 forum 3

Hi Guys. I'm trying to suspend a process by it name, but I found the sample that demontrate this using ProcessId. The problem is that I don't know the process ID of the process I want to suspend/resume. [Here is a sample I used.](https://social.msdn.microsoft.com/Forums/en-US/cdde6cef-3971-40a6-b4dd-02db963868ce/suspend-an-application?forum=vbgeneral)

Member Avatar
Member Avatar
+0 forum 1

Sometimes there are functions you want your program to perform in the background while you are busy doing other things. For example, if you are building a picture viewer application you may not want to wait until thumbnails are generated before getting on with the business of viewing the pictures. If you have ever used the [FastStone Image Viewer](http://www.faststone.org/FSViewerDetail.htm) you will have noticed the progress bar at the bottom of the screen when browsing to a new folder. That bar shows the progress of a background thread which is busy scanning the current folder. If you try to change the …

Member Avatar
Member Avatar
+3 forum 2

Hi, I got multiple threads in different classes created in this manner: private ThreadStart someName_TS; public Thread someName_Thread; public void someName() { someName_TS = new ThreadStart(someNameThread); someName_Thread = new Thread(someName_TS); someName_Thread.Start();} } private void someNameThread() { while(!Shutdown) { //Do heavy work } } The heavy work is set to a "while" statement that is always set to false unless the user wants to close the application. Now on my main form I got the following FormClosing code: if (e.CloseReason == CloseReason.UserClosing) { e.Cancel = true; guiThread.closeApp(); } Now where I think I need help is that I just made a …

Member Avatar
Member Avatar
+0 forum 3

[CODE]# -*- coding: utf-8 -*- from PyQt4 import QtGui from PyQt4.QtCore import * import sys import os class VideosToMp3(QtGui.QWidget): def __init__(self, parent = None): super(VideosToMp3, self).__init__(parent) ''' Labels and GUI ''' extension = QtGui.QWidget() download_label = QtGui.QLabel("Enter YouTube video URL:") self.download_line_edit = QtGui.QLineEdit() file_label = QtGui.QLabel("Enter file name (optional):") self.file_line_edit = QtGui.QLineEdit() mp3_filename_label = QtGui.QLabel("MP3 file name:") self.filename_line_edit = QtGui.QLineEdit() download_button = QtGui.QPushButton("Download in URL") download_file_button = QtGui.QPushButton("Download in file") cancel_button = QtGui.QPushButton("Cancel") spacer = QtGui.QSpacerItem(10, 20, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) gridLayout = QtGui.QGridLayout() gridLayout.addWidget(download_label, 0, 0) gridLayout.addWidget(self.download_line_edit, 0, 1) gridLayout.addWidget(mp3_filename_label, 1, 0) gridLayout.addWidget(self.filename_line_edit, 1, 1) gridLayout.addWidget(file_label, 2, 0) gridLayout.addWidget(self.file_line_edit, 2, 1) …

Member Avatar
Member Avatar
+0 forum 5

So I'm building this pretty simple top trumps card game as part of an assignment. I have the game logic built, the swing GUI is in place and I plan to do all the calculation on the server app and have it update the client up with the game's state, round, turn to play and decks. Obviously, I need a multitude of threads. So I've built this method which I call by pressing a button in `MainGUIServer.java`: public void startRunning() { // Initiates the server. try { while (true) { try { // Connecting and communicating. ServerThread st = new …

Member Avatar
Member Avatar
+0 forum 4

Hey guys, I'm interested in learning about simple multithreading in C++ for Windows. Does anyone have any reccommended tutorials/links thats quite good?

Member Avatar
Member Avatar
+0 forum 2

Hi Dw I'm trying to create a server that will handle simultaneous connections from clients and for simplicity I've decided to save data to the text files, it not one text file but there are many text files which will be located on the server. The clients (written in VB5.0) will connect to the server only when a user has clicked join button. I have almost more then 57 buttons which are choices a user will select only one button. I will make an example with the first two buttons. Button1 'Cow' , Button2 'Dog'. Now the client will send …

Member Avatar
Member Avatar
+0 forum 13

//I want to start a thread that set postion of a la lable here is part of the code t = new Thread(bar); t.Start(); public void bar() { while (true) { label2.Location = new Point(this.label2.Location.X + 10, this.label2.Location.Y); Thread.Sleep(1000); if (this.label2.Location.X > this.Width) { label2.Location = new Point(200-this.label2.Width + 10, this.label2.Location.Y); } } } //here is the problem //Invalid cross-thread operation: Control 'Form1' has been accessed from a thread other than the one on which it was created.

Member Avatar
Member Avatar
+0 forum 4

Quick question, the answer is eluding me on the internet. Which is unusual. When we reference and call a sub/function from a class is it automatically started on a new thread or will it join the main thread? Cheers in advance.

Member Avatar
Member Avatar
+0 forum 3

Greetings. I have a bit of situation here. I'm using symfony2 and facebook SDK to set up a web service for my IPhone and Android applications. The problem is that the background work can take quite a while. User is first redirected to facebook login page where he can proceed by accepting my facebook app permissions. So, instead of waiting for my service to complete background work, user should be notified immediately that everything is in order. Service should continue work in background and user should be unaware of it. These are the first few lines of my controller: $em …

Member Avatar
Member Avatar
+0 forum 1

Have a look at this thread... http://www.daniweb.com/web-development/databases/mysql/threads/466095/create-.mdf-file-from-mysql My machine shows seems to reformat this to plain text. So just plain page of text. Using Chrome/W7. Anybody else?

Member Avatar
Member Avatar
+0 forum 7

I created a thread as I was struggling with an assignment I was given. I was told today that I mustn't share my coding with anyone and was wondering if there was anyway to delete my thread. my thread is http://www.daniweb.com/software-development/python/threads/465305/python-prime-number-code-not-working

Member Avatar
Member Avatar
+0 forum 5

I'm trying to create a program where I can print output to my console application and entering test without being override. Is there anyway to accomplish this? Here is my simple code showing my issue: ` #include <iostream> #include <thread> #include <Windows.h> void myThread() { while (1) { std::cout << "hello world" << std::endl; Sleep(1000); } } int main() { std::thread t1(myThread); while (1) { std::cin.get(); } return 0; } `

Member Avatar
+0 forum 0

Hello! I would like some help with a piece of java code that i'm having problem. I have to make simultaneous tcp socket connections every x seconds to multiple machines, in order to get something like a status update packet. I use a Callable thread class, which creates a future task that connects to each machine, sends a query packet, and receives a reply which is returned to the main thread that creates all the callable objects. My socket connection class is : public class ClientConnect implements Callable<String> { Connection con = null; Statement st = null; ResultSet rs = …

Member Avatar
Member Avatar
+0 forum 8

Hi I am new to this forum and i was just wondering if the following scenario is implementable. Suppose a thread is reading a file and dividing it into chunks of data(lets say in the form of arraylist, where each line corresponds to a value in arraylist). Each chunk of data is associated with one thread and that thread is writing that data into a file. i want that as soon as ane line has been written,the lock should open and any thread can occupy the lock. is it possible? if yes can you provide a brief overview on how …

Member Avatar
Member Avatar
+0 forum 1

I am working on a simpler version of the following question: http://www.cs.ucf.edu/courses/cnt4714/spr2011/prog1.pdf and have simplified the problem in the following manner: SO: input pipe is PIPE4 and output pipe is PIPE0 S1: input pipe is PIPE0 and output pipe is PIPE1 S2: input pipe is PIPE1 and output pipe is PIPE2 S3: input pipe is PIPE2 and output pipe is PIPE3 S4: input pipe is PIPE3 and output pipe is PIPE4 The output that i am getting: WHO CAME?? Pipe4 and Pipe0:Position0 GRANTING ACCESS TO Pipe4 and Pipe0 WHO CAME?? Pipe0 and Pipe1:Position1 SLEEPING : 1 RELIEVING NOTIFIED Final Capacity …

Member Avatar
+0 forum 0

I am very new to thread. However I would like to make 2 threads, Thread A and Thread B. When a button is clicked Thread A starts and so does Thread B. Thread B shows a loading image and disables users from clicking any buttons whilst Thread A executes some logic code. Thread B continues to run untill the logic in thread A is executed and thus Thready A is stopped. Is it better to use a single or two thread in this case? How can I do this?

Member Avatar
Member Avatar
+0 forum 4

I have a Java code block like following: public TcpConnection(TcpSocket socket, long alive_time, ITcpConnectionListener listener) { init(socket,alive_time,listener); start(); } For the conversion in C#, When I try to replace the `start()` method with `System.Threading.ThreadStart()`, it gives an error. How can I start a thread in C#?

Member Avatar
Member Avatar
+0 forum 2

hey could anyone please tell me how to create a dialog from a background thread that is not a UI thread in Android?? something like this.. Thread t=new Thread(new Runnable() { @Override public void run() { Thread innerThread=new Thread(new Runnable() { @Override public void run() { /////***** i need to create a dialog here *****//// /////***** but the dialog doesn't appear or it closes too soon ///// to be able to record a user input *****//// } }); } });

Member Avatar
Member Avatar
+0 forum 3

Hi, I have two threads A and B. Thread A prints only odd numbers. Thread B prints only even number. I want to synchronize it in such a way that on the screen I get continues numbers. How can I do that? I was thinking of using sockets. Thread A prints and sends a message to thread B. Thread B prints and then sends a message to thread A. Any thread before printing checks for the message from other thread and prints only if they have received the message. Is this the best design or any of you have a …

Member Avatar
Member Avatar
+0 forum 3

Will there be any rating score of a thread in the future? What is the **Pro** or **Con** of it?

Member Avatar
Member Avatar
+0 forum 3

The assignment is to implement the Banker's Algorithm using pthreads and mutex locks. We implemented the Banker's Algorithm and it works fine. When we began implementing the pthreads and mutex locks we ran into problems. We know that each process is a thread, and that the mutex lock is acquired once it is inside of the Banker's Algorithm function and it is released once you leave the function. We are just confused about how the threads come into play.

Member Avatar
Member Avatar
+0 forum 1

Hi Guys I was just wondering how you stop the combo box from displaying different instances of the same value. In the combo box i have villages and towns names e.g doolin. onli thing is i have many businesses from doolin on the database so when i pull the town field for the combo box i get doolin in the cobmo box several times. How do I prevent this?? Thanks

Member Avatar
Member Avatar
+0 forum 6

I was looking at the possible solution to synchronise a bounded buffer ( like queue) using condition variables and think that we probably need two condition variables to correctly implement the synchronisation, one condition varaible will have a queue where the consumer thread(s) will be waiting to see if the buffer is not empty and another will producer (threads) will be waiting to check if the buffers are not full?

Member Avatar
Member Avatar
+0 forum 1

i'm looking for code of posting a new thread box like that found in vbulltin forums or any box like that which has basic settings as(Bold , italic, underline , add image using url, alignment , fonts type , color , size , adding codes) i don't need it for a forum but for a normal site i coded it i want to take the writing in the box using php to my sql thanks in advance

Member Avatar
Member Avatar
+0 forum 1

This Python snippet shows how to control a VPython visual 3D sphere with Tkinter GUI toolkit button clicks.

Member Avatar
+4 forum 0

Hi people. I wonder how I can free the pthreads' allocated memory? #include <pthread.h> #include <stdio.h> #include <stdlib.h> #define NUM_OF_THREADS 10 void* print_thread_id(void* tid) { printf("Greetings from thread %d\n", (*(int*)tid)); pthread_exit(NULL); } int main(int argc, char* argv[]) { pthread_t threads[NUM_OF_THREADS]; int status, i; int* n_thread; for(i = 0; i < NUM_OF_THREADS; i++) { if((n_thread = malloc(sizeof(int))) == NULL) return EXIT_FAILURE; *n_thread = i; printf("Main here. Creating thread %d\n", i); if((status = pthread_create(&threads[i], NULL, print_thread_id, n_thread)) != 0) { printf("ERROR. Thread error code: %d\n", status); exit(EXIT_FAILURE); } free(n_thread); } return EXIT_SUCCESS; } ==11701== LEAK SUMMARY: ==11701== definitely lost: 0 bytes in …

Member Avatar
Member Avatar
+0 forum 1

Hi all Just looking a creating a possible java or jsp based messenger for a web site. I have tested java based lan messengers, p2p messengers and even openfire+spark+smack instant messaging, XMPP (also called Jabber) which I admit I liked a great deal. They say dont try re-invent the wheel ect but if I wanted to go global and my messenger program was popular then I would prefer that it was mine to do with as I pleased. Its a general question and I am basically thinking aloud but would welcome any input in how to create such an application …

Member Avatar
Member Avatar
+0 forum 1

The End.